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 Winbinding
{
public partial class Form1 : Form
{
public Form1()
{
//초기화자
InitializeComponent();
}
private DataSet ds; //주수록 담을 그릇 (전역변수) 필드 선언
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);
SqlDataAdapter da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds, "AddressBook"); //채우기
//[!]바인딩
//text1의 Text속성을 ds 에 담겨 있는 AddressBook 테이블의 Name필드 연결
textBox1.DataBindings.Add("Text", ds, "AddressBook.Name");
textBox2.DataBindings.Add("Text", ds, "AddressBook.Mobile");
textBox3.DataBindings.Add("Text", ds, "AddressBook.Email");
}
//이전
private void button1_Click(object sender, EventArgs e)
{
//감소
BindingContext[ds, "AddressBook"].Position--; //레코드 이동
}
//다음
private void button2_Click(object sender, EventArgs e)
{
//증가
BindingContext[ds, "AddressBook"].Position++; //다음 레코드
}
}
} |