ado.net2.0 dataset

 

我自己弄一个表,字段Id(自增),myName(varhchar(50)),myAge(int)  

   

                    记录:                     1       Kaka             23  

                                                    2       XianXian     24  

  下面是两个方法:  

 

public   int   UpdateMy(Database   db,DataSet   myDs)  

                  {

 

   

                          DbCommand   insertCommand   =   db.GetStoredProcCommand("InsertRecord");  

                          db.AddInParameter(insertCommand,   "myName",   DbType.String,   "myName",   DataRowVersion.Current);  

                          db.AddInParameter(insertCommand,   "myAge",   DbType.Int32,   "myAge",   DataRowVersion.Current);  

   

   

                          DbCommand   delCommand   =   db.GetStoredProcCommand("DelRecord");  

                          db.AddInParameter(delCommand,   "Id",   DbType.Int32,   "Id",   DataRowVersion.Current);  

   

                          DbCommand   updateCommand   =   db.GetStoredProcCommand("UpdateRecord");  

                          db.AddInParameter(updateCommand,   "Id",   DbType.Int32,   "Id",   DataRowVersion.Current);  

                          db.AddInParameter(updateCommand,"myName",DbType.String,DataRowVersion.Current);

 

                          db.AddInParameter(updateCommand,   "myAge",   DbType.Int32,   DataRowVersion.Current);  

   

                          int   rowAffected=db.UpdateDataSet(myDs,"my",insertCommand,updateCommand,delCommand,UpdateBehavior.Standard);

 

                          return   rowAffected;    

   

                  }  

   

  //更新一个记录  

   

  public   void   update_Record()  

                  {  

   

                          Database   db   =   DatabaseFactory.CreateDatabase();  

                          DataSet   myDs   =   new   DataSet();  

                          string   sqlCommand   =   "select   *   from   my";  

                          DbCommand   dbCommand   =   db.GetSqlStringCommand(sqlCommand);  

                          string   myTable   =   "my";  

                          db.LoadDataSet(dbCommand,   myDs,   myTable);  

                          DataTable   table   =   myDs.Tables[myTable];  

                          table.Rows[0]["myName"]   =   "ShuiShui";  

                     

                          this.UpdateMy(db,myDs);  

   

                  }  

   

   

  执行后统统是:               1     Current     512  

                                            2     XianXian   24  

   

   

 

这是为什么,请高手给点指点     谢谢!!·!·!·

 

源文档 <http://cache.baidu.com/c?word=%C0%FB%D3%C3%3Bdataset%3B%B8%FC%D0%C2%3B%CA%FD%BE%DD&url=http%3A//topic%2Ecsdn%2Enet/t/20060321/10/4628187%2Ehtml&b=37&a=18&user=baidu>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值