Click here to Skip to main content
15,851,387 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
      foreach (DataRow row in mDT_PoHead.Rows)
             foreach (DataColumn col in mDT_PoHead.Columns)
                   mDT_RptHead.Rows[0][col.ColumnName] = row[col];

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.
Updated 13-Nov-11 0:21am
Amir Mahfoozi 13-Nov-11 7:46am    
what do you want to update in rptpo_head ?

1 solution

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 :)
Share this answer
Mayank Topiwala 13-Nov-11 6:21am    
Dear Naerling

mDBHelper is the object of class DBHelper that has already created in my module and with the help of static methods (like GetTable, ExecuteSQLNonQuery etc.), I can easily fetch relevant data. But the thing is without using the insert query how i can insert the data in "rptpo_head".I have already collected these data in the data table mDT_RptHead using foreach loop as shown above.

Sander Rossel 13-Nov-11 7:17am    
I don't see why you could not use the insert query. However, if your mDBHelper Object can't help you here I think you are making things hard on yourself and you should check your design.
The alternative is looping through the datatable again and writing your own update query that you can execute using a SqlCommand Object. You can pass the values of your current DataRow to the SqlCommand Object as parameters. However, you should be wary of the fact that update and insert and delete should be handled seperatly. Seems like a lot extra work if the DataAdapter already provides an Update Method that does all this work for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900