将数据表更新到数据库 [英] Update Datatable to Database

查看:77
本文介绍了将数据表更新到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是代码:-

Here''s the code :-

 DataTable mDT_RptHead = new DataTable();
 mDT_RptHead = mDBHelper.GetTable("Select * from rptpo_head");
 mDBHelper.ExecuteSQLNonQuery("delete from rptpo_head");

 DataTable mDT_PoHead = new DataTable();
 mDT_PoHead = mDBHelper.GetTable("SELECT * FROM PO_HEAD WHERE PO_NO='D0003' AND             PO_DATE =CONVERT(DATETIME,'13/11/2011',103) and profcen_cd='1'");

if (mDT_PoHead.Rows.Count > 0)
  {
      DataRow newRow = mDT_RptHead.NewRow();
      mDT_RptHead.Rows.Add(newRow);
      foreach (DataRow row in mDT_PoHead.Rows)
          {
             foreach (DataColumn col in mDT_PoHead.Columns)
                   mDT_RptHead.Rows[0][col.ColumnName] = row[col];
          }
   }




运行代码后,数据已正确插入mDT_RepHead.Now中,我想更新表"rptpo_head",以从中获取相应的数据.

需要建议.




After running the code, data properly inserted in mDT_RepHead.Now i want to update the table "rptpo_head" from which i fetch the corresponding data.

Need Suggestion.

推荐答案

这很难说,因为mDBHelper中正在发生一些魔术.
从您的其余代码来看,我认为它使用 SqlConnection [ ^ ], SqlCommand [ SqlDataAdapter [数据集 [ DataAdapter.Update方法 [^ ].
可能使用 SqlCommandBuilder对象 [ ADO.NET [
It''s a bit hard to tell since there is some magic going on in the mDBHelper.
Judging from the rest of your code I think it uses SqlConnection[^], SqlCommand[^], SqlDataAdapter[^] and DataSets[^] though.
In that case your best bet is the DataAdapter.Update Method[^].
Possibly use a SqlCommandBuilder Object[^] to auto-generate your update statements.
More on ADO.NET[^].
Hope it helps :)


这篇关于将数据表更新到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆