string connectionString = "server = (local); uid=test2; pwd=test2; database=test2; Integrated Security = true";
(local) 이라고 쓰거나, mssql 시작할 때 쓰던 그 명을 쓰면 됨. 보통 혼자할꺼니까 (local) 이라고 괄호까지 붙여서쓰자.
SqlConnection scon = new SqlConnection(connectionString);
SqlCommand scom = new SqlCommand();
scom.Connection = scon;
scom.CommandText = "select name, email from info";
scon.Open();
SqlDataReader sdr = scom.ExecuteReader();
while(sdr.Read())
{
Console.WriteLine("name : " + sdr["name"].ToString());
Console.WriteLine("email : " + sdr["email"].ToString());
}
그 외에는 그냥 따라하면 됩니다 . info라는 테이블에 name과 email이라는 열이 있어서 위와 같이했고, 따라하시는분들은
각자 개인의 테이블명과 열 명으로 수정하시면 되겠어요 :)
Visual Studio 에서의 실행결과
*
MSSQL 에서의 실행결과
'C#' 카테고리의 다른 글
[공유] C# new & override (뉴 & 오버라이드) (0) | 2019.06.26 |
---|---|
c# Window Form TreeView 삭제/추가/노드개수 (0) | 2019.06.26 |
c# DateTime 날짜포맷 (0) | 2019.06.26 |
[c#] window form / 열려있는 폼 찾기. (가져오기) (0) | 2019.06.26 |
C# string.Format 연습 (0) | 2019.06.26 |