日期:2014-05-19  浏览次数:20830 次

为什么我在dataSet中new的一条row加不进去?T.T
代码如下:
DataRow   row   =   userDs.Tables[0].NewRow();
row[POS.Common.POSParameters.USER_ID]   =txtUserID.Text;



System.Diagnostics.Debug.WriteLine( "newRowCount===== "   +   userDs.Tables[0].Rows.Count);
打印结果表明新的一行没有加进该dataSet中,这是什么原因呢?

------解决方案--------------------
DataRow row = userDs.Tables[0].NewRow();
row[POS.Common.POSParameters.USER_ID] =txtUserID.Text;
...
userDs.Tables[0].Rows.Add(row);


NewRow只是生成一个新的行,一定要把这个行加到Rows中才可以.
------解决方案--------------------
Rows.Add()

要加入 datatable中才行
------解决方案--------------------
通常先建立dataTable
而后建立DataColumn
再建立DataRow

------解决方案--------------------
DataRow row = userDs.Tables[0].NewRow();
userDs.Tables[0].Rows.Add(row);
row[POS.Common.POSParameters.USER_ID] =txtUserID.Text;
...

------解决方案--------------------
DataSet.tables[ "tablename "].Rows.add(newRowname);