Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
Questions & Answers
Tips & Tricks
 how to loop through each record in a table and check if thesame record exists or not.
Posted by sandy on  1/8/2012 3:01:22 PM Category: C#
Add to my favorites
Email to friend
Hi Folks,

My webservice is returning some records and i am capturing the same in my database.Know If any one of the record changes in the webservice returned data i want to update the same in my table as well. Can you please let me know if you have any idea. Below is my sample code.

webserviceref.webservice Class PInstance = new webserviceref.webservice ();//Created an object for webservice

DataSet ds = PInstance.GetEmployees();//thewebservice class has a web method Get
Employees whichis returnted by the webservice and iam storing in a dataset

string sqlconnection = ConfigurationSettings.AppSettings["MyConnectionstring"].ToString();

foreach (DataRow dr in ds.Tables[0].Rows)
DatabaseCls.Parameter[] parameter = new GenericDBParameter[2];
parameter[0] = new Parameter("@Empid_ID", dr[0].ToString());
parameter[1] = new Parameter("@Emp_namee", dr[1].ToString());
DatabaseCls.ExecuteQuery.Execute(sqlconnection, "Mystoreprocedure.spInsert", parameter);
//This will insert the values in my table....


catch (Exception ex)



return "success";



Post Your Reply Post New Question

 Viewer's Reply
Storing DataTable into DataBase
Answered By Moderator1 on 9/11/2012 10:06:27 AM
Hi Sandy,

Instead of looping through the database, you can convert the datatable as DataSet xml and pass the xml string as parameter to a stored procedure. This Stored procedure will do the bulk insertion of xml into your database table. Thus, you avoid looping.
Post Your Reply If you still have problem, post it again under this reply for better response.

Sponsored by
Oracle Magazine
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
Washington Technology