Update 无法找到 TableMapping

场景:Update 无法找到 TableMapping['sonproject'] 或 DataTable“sonproject”。该如何解决

Update 无法找到 TableMapping['sonproject'] 或 DataTable“sonproject”。

namespace   Database
{
        public   class   Dbase
        {
                private   string   ss   =   "Integrated   Security=SSPI;User   Id=sa;database=jindu;server=localhost ";
                public   SqlConnection   sqlcon;
                public   static   System.DateTime[]   time   =   new   System.DateTime[50];
                public   Dbase()
{
this.sqlcon=new   SqlConnection(this.ss);
                                                        sqlcon.Open();
                     
}
                public   DataSet     getdataset(string   Sqltext)
                {
                     
                        DataSet     ds=new   DataSet   ();
                        SqlDataAdapter   da   =   new   SqlDataAdapter(Sqltext,   this.ss);
                        SqlCommandBuilder   thisbuilder   =   new   SqlCommandBuilder(da);  
                        da.Fill(ds);
                        return   ds;
                }

                public   void   update(string   Sqltext,string   table)
                {
                        DataSet   ds   =   new   DataSet();
                        SqlDataAdapter   da   =   new   SqlDataAdapter(Sqltext,   this.ss);
                        SqlCommandBuilder   thisbuilder   =   new   SqlCommandBuilder(da);
                        da.Fill(ds);
                        da.Update(ds,table);
                }
}


namespace   manage
{
        public   partial   class   sonproject   :   Form
        {
........................
string   cm   =   "select     *   from   sonproject   ";
                        Dbase   db   =   new   Dbase();
                        DataSet   ds   =   new   DataSet();
                        ds   =   db.getdataset(cm);
                        DataRow   thisrow   =   ds.Tables[0].NewRow();
                       
                        thisrow   [ "父项目编号 "]=pronumtext   .Text   ;
                        thisrow   [ "子项目编号 "]=sonpronumtext   .Text   ;
                        thisrow   [ "子项目名称 "]=sonpronametext   .Text   ;
                        thisrow   [ "开始时间 "]=sonprobegindatetime   .Value   ;
                        thisrow[ "结束时间 "]   =   sonproenddatetime.Value;
                        thisrow   [ "前置子项目 "]=sonprobeforetext.Text   ;
                        thisrow   [ "负责人 "]=sonprobeforetext   .Text   ;
                        thisrow   [ "负责公司 "]=sonprocompanytext   .Text   ;
                       
                        string   tb   =   "sonproject ";
                        ds.Tables[0].Rows.Add(thisrow);
                        db.update(cm,tb);               //此处为什么会出现如题所示的错误呢
.................................
}

------解决方案--------------------
使用SqlCommanderBuilder时


DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(Sqltext, this.ss);
SqlCommandBuilder thisbuilder = new SqlCommandBuilder(da);//确保此处sqltext返回了主键信息

===================================================================
da.SelectCommand = thisbuilder .GetInsertCommand();
da.UpdateCommand = thisbuilder .GetUpdateCommand();
da.DeleteCommand = thisbuilder .GetDeleteCommand();
===================================================================
da.Fill(ds);
da.Update(ds,table);

------解决方案--------------------
针对找不到table

是因为你在da.Fill(ds)时 应当指定table的名称

da.Fill(ds,sonproject);


------解决方案--------------------
da.Fill(ds, "sonproject ");
------解决方案--------------------
da.Fill(ds);
================〉〉

da.Fill(ds,table);
------解决方案--------------------
使用SqlCommaderBuilder操作数据库时,首先要确保数据库中该表有主键


不是让你在ds中设置主键