반응형
using System.Data.SqlClient;
private String Constr = "server=<서버주소>;uid=<userName>;pwd=<PassWord>;database=<DatabaseName>";
<서버주소> 연결할 서버의 주소를 넣어준다 로컬DB 면 127.0.0.1
<UserName> 계정이름
<PassWord> 비밀번호
<DatabaseName> 사용할 DataBaseName을적어준다.
private void Data_Load()
{
var Conn = new SqlConnection(Constr);
Conn.Open();
SqlCommand sc = new SqlCommand();
sc.Connection = Conn;
sc.CommandText = "Select * from Report_Test where Company = '삼성'";
sc.CommandType = CommandType.Text;
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
sda.SelectCommand = sc;
sda.Fill(ds, "SamSung");
Conn.Close();
}
DataSet은 DataTable의 저장창고라고 생각하면된다.
해당코드에서는 SamSung이라는 이름의 DataTable 을 DataSet에 저장한것이다.
반응형
'언어 > C#' 카테고리의 다른 글
[C#] SaveFileDialog 사용 텍스트 저장하기 (0) | 2020.02.27 |
---|---|
[C#] 유효성검사 System.Text.RegularExpressions.Regex.IsMatch 사용 (0) | 2020.02.27 |
[Windows Forms] 윈폼 버튼 클릭이벤트 메시지박스 출력하기 (0) | 2020.01.22 |