代码有问题。
看看msdn中的示例把

解决方案 »

  1.   

    DataRow myRow;
    myRow = ds.Tables["Course"].NewRow();

    myRow["Course_name"] = "NortWest Trade Company"; // Add the row.
    ds.Tables["Course"].Rows.Add( myRow ); // Calling AcceptChanges on the DataSet causes AcceptChanges to be
    // called on all subordinate objects.
    //ad.Update(ds);
               ad.Update(ds);
      

  2.   

    加个try....catch(Exception ex)
    {
     Debug.Fail(ex.Message)
    }
    看暴什么错!
      

  3.   

    就算 ad.update(ds)这句有问题
    如果加入表名ad.update(ds,"Course")后就没错但是在数据库中没有添加新的数据
    如果去掉表名就会报这个:
    未处理的“System.InvalidOperationException”类型的异常出现在 system.data.dll 中。其他信息: Update 无法找到 TableMapping['Table'] 或 DataTable“Table”。
      

  4.   

    說得不夠詳細...檢查是否 1. 執行了DataAdapter.fill()?
             2. 引用了 using System.Data.Dledb?
      

  5.   

    如果表Course的其他列不允许空的话也会发生错误
      

  6.   

    我把数据库换成了sqlserver自带的数据库pubs然后用authors表,还是有异常!
      

  7.   

    DataRow myRow;
    myRow = ds.Tables["Course"].NewRow();

    myRow["Course_name"] = "NortWest Trade Company"; // Add the row.
    ds.Tables["Course"].Rows.Add( myRow ); // Calling AcceptChanges on the DataSet causes AcceptChanges to be
    // called on all subordinate objects.
    //ad.Update(ds);
               ad.Update(ds);//这句错了,后面还有一个参数:DATASET的表名,前面还应该加上下面的
    SqlCommandBuilder SqlCd = new SqlCommandBuilder(ad);
    即:
    SqlCommandBuilder SqlCd = new SqlCommandBuilder(ad);
    SqlDa.Update(ds,"Course");
      

  8.   

    其他信息: Update 无法找到 TableMapping['Table'] 或 DataTable“Table”。就是因为没有为ad的Update指明ds的表
      

  9.   

    SqlCommandBuilder SqlCd = new SqlCommandBuilder(ad);
    SqlDa.Update(ds,"Course");
    确实是这样子,我以前也碰到过这样的问题,后来也是这样子解决的,这里高手就是多!牛!