Form_Load时:我已经定义了
conn.Open();
string str;
str = "select * from khxx ";
da = new SqlDataAdapter(str, conn);
ds = new DataSet();
da.Fill(ds, "khxx");
dt=ds.Tables["khxx"];
myBind = this.BindingContext[ds, "khxx"];
SqlCommandBuilder cb = new SqlCommandBuilder(da);
this.dataGrid1.DataSource = ds;
this.dataGrid1.DataMember = "khxx";
之后,由于需要对 ds再次过滤,所以又对按钮重新写了代码:
private void button1_Click(object sender, EventArgs e)
conn.Open();
string str;
str = "select * from khxx where zt='T'";
da = new SqlDataAdapter(str, conn);
ds = new DataSet();
da.Fill(ds, "khxx");
dt=ds.Tables["khxx"];
myBind = this.BindingContext[ds, "khxx"];
SqlCommandBuilder cb = new SqlCommandBuilder(da);
this.dataGrid1.DataSource = ds;
this.dataGrid1.DataMember = "khxx";
再点击DataGrid时问题出现了:myBind.Position.ToString()这个值永远都成0了!!!
好像对于这个 myBind.Position已经失效了