dataset 更新到資料庫的問題

2021-04-07 08:33:47 字數 1302 閱讀 4505

string everyconn = common.commonutility.geteveryconn ();

//   empresource mpevery = new empresource(everyconn);

//   dataset dse= mpevery.mpresourcelist ();

//   datatable dte=dse.tables[0];

dataset dse = new dataset();

system.data.sqlclient.sqlconnection econn = new sqlconnection(everyconn);

string strsql = " select * from empresource";

econn.open();

//sqlcommand everycmd = new sqlcommand(strsql,econn);

//string srctable ="empresource";

sqldataadapter sqladapter = new sqldataadapter(strsql,econn);

sqlcommandbuilder scb = new sqlcommandbuilder(sqladapter);

//everycmd.executenonquery();

sqladapter.fill(dse,"empresource");

datatable dte=dse.tables["empresource"];

dte.primarykey = new datacolumn ;

empresource mp = new empresource(constr);

dataset ds = mp.mpresourcebympid (pubmpid);

datatable dt = ds.tables[0];

int rowcount = dt.rows.count;

if(rowcount>0)}}

dse.merge(ds);

//   foreach(datarow dr in dse.tables[0].rows)

//   

//response.write (dse.haschanges());

sqladapter.update(dse,"empresource");

//dse.acceptchanges();

econn.dispose();

不報錯,可是就是更新不了資料庫

而且dse.haschanges()一直是flase

DataSet更新到資料庫總結

最近在工作中再次遇到了將dataset中的資料全部插入資料庫的情況。這種情況以前也處理過,很久沒用又忘記了,今天特別總結一下這種情況的處理方式。首先,用select語句查詢需要插入資料的表,用top 1查一行就夠了,這個是為了給sqldataadapter生成表的架構用的。1string strsq...

DataSet更新到資料庫總結

首先,用select語句查詢需要插入資料的表,用top 1查一行就夠了,這個是為了給sqldataadapter生成表的架構用的。string strsql select from tableneedtoupdate 2sqldataadapter da new sqldataadapter str...

DataSet更新資料庫

思路是這樣的 先查詢,繫結資料集 要更新的資料集需要設定為當前模組的變數 等你在datagridview修改資料後繼續進行下面的操作 然後是再在其他的事件中提交修改 比如 你在某個窗體內定義 sqlconnection conn dataset ds new dataset sqlcommand c...

將DataTable中的修改更新到資料庫中

前提 資料庫aaa,有表bbb,欄位為b varchar 10 如下 private void button1 click object sender,system.eventargs e private void form2 load object sender,system.eventargs ...

使用java將Execl資料更新到資料庫表中

在工作中,遇見資料的匯入。有的是文字檔案,有的是在excel 裡面的資料。我這次的工作就是講excel表中的資料更新到資料的表裡面。首先將execl格式轉換成.csv並且轉成utf 8格式。廢話不多說直接寫 override public void exlh throws exception lis...