private void button1_Click(object sender, EventArgs e)
{
try
{
string sqlconn = "server=" + textBox1.Text.Trim() + "\\SQLEXPRESS;database=VoltageMessage;uid=sa;pwd=666666";
SqlConnection conn = new SqlConnection(sqlconn);
//SqlConnection conn1 = new SqlConnection("server=localhost\\SQLEXPRESS;database=VoltageMessage;uid=sa;pwd=666666");
SqlConnection conn1 = new SqlConnection("server=.\\SQLEXPRESS;database=VoltageMessage;uid=sa;pwd=666666");
string sqlstr1="select * from MessageScout";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sqlstr1, conn);
da.Fill(ds, "MessageScout");
DataSet ds1 = new DataSet();
SqlDataAdapter da1 = new SqlDataAdapter(sqlstr1, conn1);
da1.Fill(ds1, "MessageScout");
ds1.Merge(ds, true);
dataGridView1.DataSource = ds1.Tables[0];
SqlCommandBuilder sb = new SqlCommandBuilder(da1);
da1.Update(ds1, "MessageScout");
ds1.Tables[0].AcceptChanges();
MessageBox.Show("更新成功!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
执行成功,可数据库根本就没有更新和新数据插入!
[此贴子已经被作者于2007-9-29 13:58:01编辑过]