100分﹗C#中SqlDataApter.update()使用經驗及技巧 ,C#新手請學習之﹐高手請指點之
*******************************************************************
更多內容請去我的blog:
http://blog.csdn.net/lanpeng/archive/2007/07/27/1710824.aspx
******************************************************************
C#新手請學習之﹐高手請指點之﹗
我原來是用delphi7.0開發ERP系統﹐從2007年開始轉向C#2005,可是在做測試數據保存時總出現如下錯誤﹕
Update requires a valid InsertCommand when passed DataRow collection with new rows.
當時很納悶。
部分代碼如下﹕
scn.ConnectionString = GlobMsg.DbConnection;
scn.Open();
SqlCommand scmdpc_hd = new SqlCommand();
scmdpc_hd.Connection = scn;
scmdpc_hd.CommandText = "select * from pc_hd ";
scmdpc_hd.CommandType = CommandType.Text;
SqlCommand scmdpc_ln = new SqlCommand();
scmdpc_ln.Connection = scn;
scmdpc_ln.CommandText = "select * from pc_ln ";
scmdpc_ln.CommandType = CommandType.Text;
//SqlDataAdapter sda_PC_HD = new SqlDataAdapter( "select * from pc_hd ",scn );
sda_PC_HD.SelectCommand = scmdpc_hd;
sda_PC_HD.Fill(ds, "pc_hd ");
//SqlDataAdapter sda_PC_LN = new SqlDataAdapter( "select * from pc_ln ",scn);
sda_PC_LN.SelectCommand = scmdpc_ln;
sda_PC_LN.Fill(ds, "pc_ln ");
dvpc_hd = ds.Tables[ "