private DataTable dt;
// private DataSet dsScore;
private void Frm5_6_Load(object sender, EventArgs e)
{
con.conDataBase();
string sql = "select * from score";
SqlCommand sqlCommand = new SqlCommand(sql ,con.coon );
SqlDataAdapter da = new SqlDataAdapter(sql, con.coon);
dt = new DataTable();
//dsScore=new DataSet() ;
da.Fill(dsScore,"score");
textBox1.DataBindings.Add(new Binding("Text", dt, "score.studID"));
dataGridView1.DataSource = dt;
dataGridView1.DataMember = "score";
}
不行
private DataTable dt;
private DataSet dsScore;
private void Frm5_6_Load(object sender, EventArgs e)
{
con.conDataBase();
string sql = "select * from score";
SqlCommand sqlCommand = new SqlCommand(sql ,con.coon );
SqlDataAdapter da = new SqlDataAdapter(sql, con.coon);
dt = new DataTable();
dsScore=new DataSet() ;
da.Fill(dsScore,"score");
textBox1.DataBindings.Add(new Binding("Text", dsScore, "score.studID"));
dataGridView1.DataSource = dsScore;
dataGridView1.DataMember = "score";
}
可以运行,为啥,大哥们答下
dataGridView1.DataSource = dt;dt里面没有数据呀~
上面一段程序,你那一行 da.Fill(dsScore,"score"); 不会报错?你这里还是填充了 dsScore ,试着把这里的 dsScore 改成 dt ,没有问题的
dt = new DataTable();
//dsScore=new DataSet() ;
da.Fill(dsScore,"score");
textBox1.DataBindings.Add(new Binding("Text", dt, "score.studID"));
---以上没有看出有填充DataTable数据的动作
自己打个点,看填充的DT里面有记录没有,看DT有没有score.studID字段,就知道为什么了