Last post Apr 06, 2010 02:10 AM by Das.Sandeep
Member
6 Points
27 Posts
Dec 02, 2009 05:57 AM|Anishnow|LINK
Hi friends
I 'm having bulk data of 2000 records in a dataset and it should be inserted in to database table all at once .can anyone provide me with working code....Its very urgent
Dataset to Database
251 Points
81 Posts
Dec 03, 2009 07:11 AM|israa17|LINK
hey , you can just use a foreach loop to loop through all rows in the dataset and insert them with an insert query into the database
Participant
1188 Points
607 Posts
Dec 08, 2009 05:19 AM|hemant.yadav|LINK
You can use the Foreach statement
foreach (DataRow theRow in thisDataSet.Tables["Testing"].Rows) {
// write your insert statement here. fecting each row from dataset to datarow.
String Query = "Insert into test1 (Name,Salary) values('"+theRow["Name"].tostring()+"',"+theRow["Salary"].tostring()+")" }
or you can use the for loop as bellow
for(int ind=0;ind < thisDataSet.Tables["Testing"].Rows.Count;ind++) {
String Query = "Insert into test1 (Name,Salary) values('"+thisDataSet.Tables["Testing"].[ind]["Name"].tostring()+"',"+thisDataSet.Tables["Testing"].[ind]["Salary"].tostring()+")";
}
<input id="gwProxy" type="hidden"><input onclick="jsCall();" id="jsProxy" type="hidden">
None
0 Points
5 Posts
Apr 06, 2010 02:00 AM|OmPrakash566|LINK
You can use SqlCommandBuilder object and update the database table at once from the dataset
System.Data.SqlClient.SqlCommandBuilder sqlCommand = new System.Data.SqlClient.SqlCommandBuilder(yourSqlDataAdapter); yourSqlDataAdapter.Update(dataSet.Tables["newTable"]);
Star
8783 Points
2327 Posts
Apr 06, 2010 02:10 AM|Das.Sandeep|LINK
INSERT INTO [dbo].[TableName]([Name] ,[Salary]) VALUES ( 'sandeep',6546203),('Das',53739234)
You can append this in single query with comma seprator and execute. It will work for you.
Member
6 Points
27 Posts
insert data from dataset to database table using vb.net
Dec 02, 2009 05:57 AM|Anishnow|LINK
Hi friends
I 'm having bulk data of 2000 records in a dataset and it should be inserted in to database table all at once .can anyone provide me with working code....Its very urgent
Dataset to Database
Member
251 Points
81 Posts
Re: insert data from dataset to database table using vb.net
Dec 03, 2009 07:11 AM|israa17|LINK
hey , you can just use a foreach loop to loop through all rows in the dataset and insert them with an insert query into the database
Please Mark as answer if it was helpful for you
Participant
1188 Points
607 Posts
Re: insert data from dataset to database table using vb.net
Dec 08, 2009 05:19 AM|hemant.yadav|LINK
You can use the Foreach statement
foreach (DataRow theRow in thisDataSet.Tables["Testing"].Rows)
{
// write your insert statement here. fecting each row from dataset to datarow.
String Query = "Insert into test1 (Name,Salary) values('"+theRow["Name"].tostring()+"',"+theRow["Salary"].tostring()+")"
}
or you can use the for loop as bellow
for(int ind=0;ind < thisDataSet.Tables["Testing"].Rows.Count;ind++)
{
// write your insert statement here. fecting each row from dataset to datarow.
String Query = "Insert into test1 (Name,Salary) values('"+thisDataSet.Tables["Testing"].[ind]["Name"].tostring()+"',"+thisDataSet.Tables["Testing"].[ind]["Salary"].tostring()+")";
}
<input id="gwProxy" type="hidden"><input onclick="jsCall();" id="jsProxy" type="hidden">
<div id="refHTML"></div>Software consultant India (.NET Expert)
Skype: si.hemant
Email: truecodemaster@gmail.com
Website:http://www.truecodemasters.com
None
0 Points
5 Posts
Re: insert data from dataset to database table using vb.net
Apr 06, 2010 02:00 AM|OmPrakash566|LINK
You can use SqlCommandBuilder object and update the database table at once from the dataset
System.Data.SqlClient.SqlCommandBuilder sqlCommand = new System.Data.SqlClient.SqlCommandBuilder(yourSqlDataAdapter);
yourSqlDataAdapter.Update(dataSet.Tables["newTable"]);
Star
8783 Points
2327 Posts
Re: insert data from dataset to database table using vb.net
Apr 06, 2010 02:10 AM|Das.Sandeep|LINK
INSERT INTO [dbo].[TableName]([Name]
,[Salary])
VALUES ( 'sandeep',6546203),('Das',53739234)
You can append this in single query with comma seprator and execute. It will work for you.
Please give us feedback no matter whether you get your answer.
Please "Mark as Answer" if it's useful for you.
Regards,
Sandeep