这是我的代码,否则条件不执行SqlCommand cmd = new SqlCommand(@"DELETE FROM Demo_Table WHERE (ID = '"+textBox1.Text+"')",con);cmd.ExecuteNonQuery();DataTable dt = new DataTable();SqlDataAdapter sda = new SqlDataAdapter(cmd);sda.Fill(dt);count = Convert.ToInt32(dt.Rows.Count.ToString());if ((textBox1.Text == string.Empty) && (textBox2.Text == string.Empty)){ MessageBox.Show("Provide ID and PASSWORD"); textBox1.Clear(); textBox2.Clear(); textBox1.Focus();}else if (textBox1.Text == string.Empty){ MessageBox.Show("select ID to delete record"); textBox2.Clear(); textBox1.Focus();}else if (count == 0){ MessageBox.Show("wrong ID");}else{ MessageBox.Show("Record Deleted");}请帮助…………
3 回答
胡说叔叔
TA贡献1804条经验 获得超8个赞
我认为计数应该是查询中的 RowsAffected,而不是网格中的行数。
count = cmd.ExecuteNonQuery();
//count = Convert.ToInt32(dt.Rows.Count.ToString());
- 3 回答
- 0 关注
- 137 浏览
添加回答
举报
0/150
提交
取消