该程序运行之后数据没在textbox控件中显示,请问需要修改哪里

该程序运行之后数据没在textbox控件中显示,请问需要修改哪里

问题描述:

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();
    }

}

}

如果你可以StuID重复的话,把dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };这句删除,否则就把
dt.Rows.Add("09001", "谢明明", "男", 19, "软件091");
修改成
dt.Rows.Add("09003", "谢明明", "男", 19, "软件091");

你的 StuID 出现重复的 09001,出错了啊。