using System.Data.SqlClient;
namespace 学生信息浏览
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
BindingSource bs = new BindingSource();
private void Form1_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet("student2");
DataTable dt = new DataTable("T_Student");
dt.Columns.Add("StuID", typeof(string));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Sex", typeof(string));
dt.Columns.Add("Age", typeof(short));
dt.Columns.Add("Class", typeof(string));
dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };
dt.Rows.Add("09001","王小玲","女",18,"软件091");
dt.Rows.Add("09002", "张伟", "男", 20, "软件092");
dt.Rows.Add("09001", "谢明明", "男", 19, "软件091");
ds.Tables.Add(dt);
bs.DataSource = ds.Tables[0];
txtNo.DataBindings.Add("Text", bs, "StuID");
txtName.DataBindings.Add("Text", bs, "Name");
txtSex.DataBindings.Add("Text", bs, "Sex");
txtAge.DataBindings.Add("Text", bs, "Age");
txtClass.DataBindings.Add("Text", bs, "Class");
}
private void btnPrevious_Click(object sender, EventArgs e)
{
bs.MovePrevious();
}
private void btnNext_Click(object sender, EventArgs e)
{
bs.MoveNext();
}
}
}