using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient; namespace DataGridApp
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Data.DataSet dataSet1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button button1;
private System.Data.OleDb.OleDbCommand oleDbCommand1; private OleDbCommandBuilder cb;
private OleDbDataAdapter da; /// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{ private void Form1_Load(object sender, System.EventArgs e)
{
//string ConStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Sql_Sever\百里鲜\diaocha\fwdc\fwdc\bin\Debug\sjk.mdb";
string ConStr=@"Provider=SQLOLEDB; Data Source=(local); Initial Catalog=sjk;User ID=sa; Password=sa";
try
{
// Get Data from multiple tables table 
string SQL = "SELECT * FROM 调查"; OleDbConnection Conn = new OleDbConnection(ConStr);
      
// Create a SqlCommand object 
oleDbCommand1 = new OleDbCommand(SQL, Conn); // Create a SqlDataAdapter object 
da = new OleDbDataAdapter();
da.SelectCommand = oleDbCommand1; // Create a SqlCommandBuilder object 
cb = new OleDbCommandBuilder(da); // Fill DataSet with data from Employees table 
da.Fill(dataSet1, "Employees"); // Bind the DataGrid at run time 
dataGrid1.SetDataBinding(dataSet1, "Employees");
}
catch(Exception ex)
{
Console.WriteLine("err {0}",ex.Message);
}
} private void button1_Click(object sender, System.EventArgs e)
{
  DataSet dsUP=dataSet1.GetChanges();
da.Update(dsUP, "Employees");

}
}
}----------------------------------------------------------------------
问题出现了,如果使用下面的连接参数
string ConStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Sql_Sever\百里鲜\diaocha\fwdc\fwdc\bin\Debug\sjk.mdb";//???只有使用 oledb 才可以update 吗?
当改完 DATAGRID 后,点击 button1就会产生 下面的错误======================================================================================
未处理的“System.InvalidOperationException”类型的异常出现在 system.data.dll 中。其他信息: 对于不返回任何键列信息的 SelectCommand 不支持 UpdateCommand 的动态 SQL 生成=====================================================================================
苦恼啊,
希望有人回复~~~~
感谢