Programming/C#
C# DB연결하기
분노의블로그
2010. 2. 23. 12:43
반응형
string connectionString = @"Server=서버명;
user id=로그인ID;
password=비밀번호;
database=DATABASE이름;
Integrated Security=true;"; //윈도우인증일때 사용
password=비밀번호;
database=DATABASE이름;
Integrated Security=true;"; //윈도우인증일때 사용
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
string query = "Select * from dbo.Employee where EmployeeID = @EmployeeID";
SqlCommand command = new SqlCommand(query, conn);
//StoredProcedure 사용
// command.CommandType = CommandType.StoredProcedure;
/////////////////////
command.Connection = conn;
command.CommandTimeout = 0;
command.Parameters.Add("@EmployeeID", SqlDbType.NVarChar);
command.Parameters["@EmployeeID"].Value = "1";
command.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(dt);
반응형