日期:2014-05-20  浏览次数:20375 次

如何更新dataset?
SqlDataAdapter   da   =   new   SqlDataAdapter( "select   *   from   测点信息 ",   conn);
                DataSet   ds   =   new   DataSet();
       
                ds.ReadXmlSchema(new   StringReader(SchemaStr));
                ds.ReadXml(new   StringReader(XmlStr));
               
                SqlCommandBuilder   commandBuilder   =   new   SqlCommandBuilder(da);
                da.Update(ds,   "测点信息 ");

执行update后,查询表里的数据,发现是执行的是插入操作。

增加:
                ds.Tables[0].Rows[0].AcceptChanges();
                ds.Tables[0].Rows[0].SetModified();

执行update后,表数据无变化,不知道哪里出了错。

------解决方案--------------------
要先把数据查到到dataset中
------解决方案--------------------

da.UpdateCommand = your update command;

ds.Tables[0].Rows[0][ "yourcolumn "]= new value;

da.Update(ds, "测点信息 ");
------解决方案--------------------
DataAdapter的update