你的数据适配器配置了InsertCommand命令了吗?
如果是用的IDE中的数据适配器,在自动弹出的向导中,你确定你的每一步操作均无问题?
数据库中,有唯一标识字段吗?如果没有,必须添加一个。

解决方案 »

  1.   

    给你帖个经典的例子吧using System;
    // use ADO.NET namespace
    using System.Data;
    // use OLE DB .NET Data Provider
    using System.Data.OleDb;class DataAddRowExample
    {
    public static void Main() 
    {
    // connect to NWIND MS Access example with OLE DB
    OleDbConnection thisConnection = new OleDbConnection(
    @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\TMP\NWIND.MDB");
    // open connection
    thisConnection.Open();
    // create DataAdapter object for update and other operations
    OleDbDataAdapter thisAdapter = new OleDbDataAdapter( 
    "SELECT CustomerID, CompanyName FROM Customers", thisConnection);
    // create CommandBuilder object to build SQL commands
    OleDbCommandBuilder thisBuilder = new OleDbCommandBuilder(thisAdapter);
    // create DataSet to contain related data tables, rows, and columns
    DataSet thisDataSet = new DataSet();
    // fill DataSet using query defined previously for DataAdapter
    thisAdapter.Fill(thisDataSet, "Customers"); Console.WriteLine("# rows before change: {0}",
    thisDataSet.Tables["Customers"].Rows.Count); DataRow thisRow = thisDataSet.Tables["Customers"].NewRow();
    thisRow["CustomerID"] = "ZACZI";
    thisRow["CompanyName"] = "Zachary Zithers Ltd.";
    thisDataSet.Tables["Customers"].Rows.Add(thisRow); Console.WriteLine("# rows after change: {0}",
    thisDataSet.Tables["Customers"].Rows.Count); thisAdapter.Update(thisDataSet, "Customers");
    Console.WriteLine("name after change: {0}",
    thisDataSet.Tables["Customers"].Rows[9]["CompanyName"]); thisConnection.Close();
    }
    }