是C#的SqlServer連接,沒對(duì)應(yīng)的標(biāo)簽只能選擇差不多的了。?public int UpdateByDataSet(DataSet ds, string strTableName) ? ?{ ? ? ? ?try ? ? ? ?{ ? ? ? ? ? ?SqlConnection sqlConn = new SqlConnection(strConn); ? ? ? ? ? ?SqlDataAdapter adapter = new SqlDataAdapter(); ? ? ? ? ? ?string strsql = "select * from " + strTableName; ? ? ? ? ? ?SqlCommand myCommand = new SqlCommand(strsql, sqlConn); ? ? ? ? ? ?adapter.SelectCommand = myCommand; ? ? ? ? ? ?SqlCommandBuilder myBuilder = new SqlCommandBuilder(adapter);? ? ? ? ? ? ? ? myBuilder.RefreshSchema(); ? //必須用這個(gè)來刷新 ? ? ? ? ? ?adapter.Update(ds, strTableName);? ? ? ? ? ? ? ? ds.AcceptChanges(); ?//必須有這個(gè)來讓ds接受更改 ? ? ? ? ? ?return 0; ? ? ? ?} ? ? ? ?catch (Exception ex) ? ? ? ?{ ? ? ? ? ? ?MessageBox.Show(ex.ToString()); ? ? ? ? ? ?return -1; ? ? ? ?} ? ?}
- 0 回答
- 0 關(guān)注
- 6191 瀏覽
添加回答
舉報(bào)
0/150
提交
取消