Database.UpdateDataSet

刚开始时尝试用以下代码来更新DataSet:

None.gif Database db  =  DatabaseFactory.CreateDatabase();
None.gif
None.gif
string  strSql  =   " Select ProductID, ProductName, CategoryID, UnitPrice, LastUpdate From Products " ;
None.gifDbCommand command 
=  db.GetSqlStringCommand(strSql);
None.gifDataSet ds 
=  db.ExecuteDataSet(command);
None.gif
None.gif
None.gifDbCommand insertCommand 
=  db.GetStoredProcCommand( " AddProduct " );
None.gifdb.AddInParameter(insertCommand, 
" ProductName " , DbType.String, DataRowVersion.Current);
None.gifdb.AddInParameter(insertCommand, 
" CategoryID " , DbType.Int32, DataRowVersion.Current);
None.gifdb.AddInParameter(insertCommand, 
" UnitPrice " , DbType.Currency, DataRowVersion.Current);
None.gif
None.gifDbCommand deleteCommand 
=  db.GetStoredProcCommand( " DeleteProduct " );
None.gifdb.AddInParameter(deleteCommand, 
" ProductID " , DbType.Int32, DataRowVersion.Current);
None.gif
None.gifDbCommand updateCommand 
=  db.GetStoredProcCommand( " UpdateProduct " );
None.gifdb.AddInParameter(updateCommand, 
" ProductID " , DbType.Int32, DataRowVersion.Current);
None.gifdb.AddInParameter(updateCommand, 
" ProductName " , DbType.String, DataRowVersion.Current);
None.gifdb.AddInParameter(updateCommand, 
" LastUpdate " , DbType.DateTime, DataRowVersion.Current);
None.gif
ExpandedBlockStart.gifContractedBlock.gifds.Tables[
0 ].Rows.Add( new   object []  dot.gif { DBNull.Value, "Added from program"1326 } );
None.gifdb.UpdateDataSet(ds, ds.Tables[
0 ].TableName, insertCommand, updateCommand, deleteCommand, UpdateBehavior.Standard);
None.gif

但是失败了,后来仔细比较QuickStart中的代码后才发现应该使用Database.AddInParameter(DbCommand command,string name,DbType dbType,string sourceColumn,object value)这个方法,查了一下帮助文档,对比如下:

1.public void AddInParameter(DbCommand command,string name,DbType dbType,object value)
Parameter
  command:The command to add the parameter;
  name:The name of the parameter;
  dbType:One of the DbType values;
  values:The value of the parameter;

2.public void AddInParameter(DbCommand command,string name,DbType dbType,string sourceColumn,object value)
Parameter
  command:The command to add the parameter;
  name:The name of the parameter;
  dbType:One of the DbType values;
  sourceColumn:The name of the source column mapped to the DataSet and used for loading or returning the value;
  values:The value of the parameter;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值