Save Multiple Rows of Datagrid into SqlServer table by single Button Click

Posted by Sapna under VB.NET on 2/14/2010 | Views : 8635 | Status : [Member] | Replies : 4
I have a combobox in which i store Purchase_Order No.As i select the purchase Order No,i get all the list of items of that purchase order in the datagrid now i want to save these records in Delivery Challan table by jst a single button click. The no. of rows may vary as per i change the Purchase Order No.Plz Help Its urgent.How can i do this,plz help.




Responses

Posted by: Abhi2434 on: 2/14/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
I guess you need to loop through all the DataRow elements that you need to insert and invoke Insert SQL for each of those individually.

You can make use of SqlBulk Insert as well If you want to.
Or you can also use dataAdapter.Update(yourtable);

Any approach you want

www.abhisheksur.com

Sapna, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 2/15/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
if you binded the Datagrid with a Dataset you can use the Update Function of the dataadpter. Look at how i did it in this Article

http://www.codeproject.com/KB/cs/N-Tier22.aspx

Thank you for Posting at DotnetFunda

Vuyiswa Maseko


Thank you for posting at Dotnetfunda
[Administrator]

Sapna, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 2/16/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
I guess this might help you :

Bulk insert into database using OpenXML :
http://www.codeproject.com/KB/database/generic_OpenXml.aspx
It will be faster than other technique as you are working with an XML Document created in server itself before doing the actual insert.

.NET 2.0 has a new flexibility of buik insert to database as well. You might also try that using :
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy(VS.80).aspx


I hope this would definitely help you in your problem.

Cheers.

www.abhisheksur.com

Sapna, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 2/18/2010 [Member] Bronze

Up
0
Down
Check
http://www.eggheadcafe.com/community/aspnet/14/48252/manipulating-data-in-a-da.aspx

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Sapna, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response