为什么SqlCommandBuilder更新不了数据库内容?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace AsyncDemo
{
public partial class Form2 : Form
{
private SqlDataAdapter da = null;
private DataSet ds = null;
public Form2()
{
InitializeComponent();
}
private void cmdSearch_Click(object sender, EventArgs e)
{
DBBase db = new DBBase();
da = new SqlDataAdapter("select * from testa", db.GetVisioTestDBConnection());
ds = new DataSet();
da.Fill(ds, "TestA");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "TestA";
}
private void cmdUpdate_Click(object sender, EventArgs e)
{
SqlCommandBuilder cb = new SqlCommandBuilder(da);
try
{
int iis = da.Update(ds, "TestA");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void cmdDelete_Click(object sender, EventArgs e)
{
//dataGridView1.Rows.Remove(dataGridView1.CurrentRow);
ds.Tables["TestA"].Rows.RemoveAt(dataGridView1.CurrentRow.Index);
ds.Tables["TestA"].AcceptChanges();
}
}
}