大哥们,这是咋整的
我想删除一条记录报错了
代码: private SqlDataAdapter da;
private DataSet dsScore;
int cur;
private void Frm5_6_Load(object sender, EventArgs e)
{
con.conDataBase();
string sql = "select * from score";
SqlCommand sqlCommand = new SqlCommand(sql ,con.coon );
da = new SqlDataAdapter(sql, con.coon);
// dt = new DataTable();
dsScore=new DataSet() ;
// dt = new DataTable();
// da.Fill(dt);
da.Fill(dsScore,"score");
SqlCommandBuilder builder = new SqlCommandBuilder(da);
this.BindingContext[dsScore, "score"].PositionChanged += new EventHandler(BingingManagerBase_PositionChanged );
textBox1.DataBindings.Add(new Binding("Text", dsScore, "score.studID"));
// dataGridView1.DataSource = dt;
dataGridView1.DataSource = dsScore;
dataGridView1.DataMember = "score";
}
private void ShowPosition()
{
int iCnt, iPos;
iCnt = this.BindingContext[dsScore, "score"].Count;
iPos = this.BindingContext[dsScore, "score"].Position + 1;
if (iCnt == 0)
{
groupBox1.Text = "jgj";
}
else
{
groupBox1.Text = iPos.ToString() + "of" + iCnt.ToString();
}
}
private void BingingManagerBase_PositionChanged(object sender, EventArgs e)
{
ShowPosition();
}
private void button9_Click(object sender, EventArgs e)
{
dsScore.Tables["score"].Rows[this.BindingContext[dsScore, "score"].Position].Delete();
da.Update(dsScore ,"score");
}
score表里没有主键?
还是专家厉害,一针见血。
我倒是看这代码的 规范性了 唉 ,差距啊。
从调试提示来看,好像是没有主键所致.SqlCommandBuilder 效率也许不太高.客户端的程序用也许无仿.