现在更新可以成功实现,但是button2删除却没有成功。什么原因.
private void button1_Click(object sender, EventArgs e)
{
SqlCommandBuilder updates = new SqlCommandBuilder(find_do);
find_do.UpdateCommand = updates.GetUpdateCommand();
find_do.Update(ds,"rs");
dataGridView1.Update();
} private void button2_Click(object sender, EventArgs e)
{
SqlCommandBuilder del = new SqlCommandBuilder(find_do);
find_do.DeleteCommand = del.GetDeleteCommand();
find_do.Update(ds, "rs");
dataGridView1.Update();
}
private void button1_Click(object sender, EventArgs e)
{
SqlCommandBuilder updates = new SqlCommandBuilder(find_do);
find_do.UpdateCommand = updates.GetUpdateCommand();
find_do.Update(ds,"rs");
dataGridView1.Update();
} private void button2_Click(object sender, EventArgs e)
{
SqlCommandBuilder del = new SqlCommandBuilder(find_do);
find_do.DeleteCommand = del.GetDeleteCommand();
find_do.Update(ds, "rs");
dataGridView1.Update();
}
一种情况是你构造的 Sql 语句有问题
private DataSet ds; private void Form4_Load(object sender, EventArgs e)
{
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
SqlConnection conn = new SqlConnection(conn_str);
SqlCommand cmd = new SqlCommand(sql_str,conn);
find_do = new SqlDataAdapter();
find_do.SelectCommand = cmd; ds = new DataSet();
find_do.Fill(ds,"rs");
dataGridView1.DataSource =ds.Tables["rs"];
dataGridView1.Columns[0].FillWeight = 50;
dataGridView1.Columns[1].FillWeight = 50;
dataGridView1.Columns[2].FillWeight = 50;
dataGridView1.Columns[3].FillWeight = 260;
dataGridView1.Columns[4].FillWeight = 70;
dataGridView1.Columns[5].FillWeight = 70;
dataGridView1.Columns[3].ReadOnly = true;
dataGridView1.Columns[5].ReadOnly = true;
} private void button1_Click(object sender, EventArgs e)
{
SqlCommandBuilder updates = new SqlCommandBuilder(find_do);
find_do.UpdateCommand = updates.GetUpdateCommand();
find_do.Update(ds,"rs");
dataGridView1.Update();
} private void button2_Click(object sender, EventArgs e)
{
SqlCommandBuilder del = new SqlCommandBuilder(find_do);
find_do.DeleteCommand = del.GetDeleteCommand();
find_do.Update(ds, "rs");
dataGridView1.Update();
}
随便一看就知道不是全部代码的菜鸟经过
变量sql_str从天上掉下来的啊,该发的不发。。
SqlCommandBuilder delete = new SqlCommandBuilder(find_do);
find_do.DeleteCommand = delete.GetDeleteCommand();
dataGridView1.Rows.Remove(dataGridView1.CurrentRow);
find_do.Update(ds, "rs");
dataGridView1.Update();
我之所以没写SQL是因为我认为和SQL语句没什么关系。