using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WinCommandBuilder
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private SqlDataAdapter da;
private DataTable dt;
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection
("server=.;database=AddressBook;uid=AddressBook;pwd=1234;");
SqlCommand cmd = new SqlCommand
("Select *From AddressBook", con);
da = new SqlDataAdapter(cmd);
dt = new DataTable("Addressbook");
//Select를 기준으로 Insert,Update,Delete문 자동 생성 :PK가 있어야 한다
SqlCommandBuilder scb = new SqlCommandBuilder(da);
SqlCommandBuilder
- 연결된 SQL Server 데이터베이스에 Dataset의 변경 내용을
조정하는 데 사용되는 단일 테이블 영향을 차등으로 생성
- 이 클래스는 상속 될 서 사용이 불가능
- public생성자에 의해 오버로드 되었습니다. SqlCommandBuiler
클래스의 새 인스턴스를 초기화 하고 있습니다. |
da.Fill(dt); //채우기
this.dataGridView1.DataSource = dt;
}
private void button1_Click(object sender, EventArgs e)
{
da.Update(dt); //CRUD 실행
}
}
} |