-
Sep 1st, 2010, 07:56 PM
#1
Thread Starter
Lively Member
how to insert multiple rows from datagrid to database in vb.net
i have a datagrid contol with multiple rows. my database structure and datagridview stucture is same.
now how to insert multiple rows from datagrid to database in vb.net
please give a sample code for this
-
Sep 1st, 2010, 08:05 PM
#2
Re: how to insert multiple rows from datagrid to database in vb.net
Is this question related to this thread:
http://www.vbforums.com/showthread.php?t=626388
You know, the one where I asked:
So, the data is NOT going to be saved to a database?
and you said:
-
Sep 1st, 2010, 08:12 PM
#3
Thread Starter
Lively Member
Re: how to insert multiple rows from datagrid to database in vb.net
yes. of course.
at first i need to collect more than one record in my datagridview. after collecting the record. i need to insert the datgridview values into my database.......
-
Sep 1st, 2010, 08:20 PM
#4
Re: how to insert multiple rows from datagrid to database in vb.net
So, why did you say that it wasn't going to be saved when I asked if it was? Did you not think that maybe I was asking that question for a reason? My answer to your question was going to be different depending on whether the data was to be saved to a database or not. If you're going to ask for our help then the least you can do is provide accurate information when we ask for it because otherwise you're wasting our time.
-
Sep 1st, 2010, 08:28 PM
#5
Thread Starter
Lively Member
Re: how to insert multiple rows from datagrid to database in vb.net
yes Mr.jmcilhinney that was my mistake.
is there any way to insert multiple rows from datagrid to database ?
-
Sep 2nd, 2010, 05:25 AM
#6
Thread Starter
Lively Member
Re: how to insert multiple rows from datagrid to database in vb.net
is there any way to insert multiple rows from datagrid to database ?
-
Sep 2nd, 2010, 08:03 AM
#7
Re: how to insert multiple rows from datagrid to database in vb.net
There may be a better way, but you can always build an INSERT statement in a loop.
VB6 Library
If I helped you then please help me and rate my post!
If you solved your problem, then please mark the post resolved
-
Sep 2nd, 2010, 06:24 PM
#8
Re: how to insert multiple rows from datagrid to database in vb.net
Follow the CodeBank link in my signature and check out my thread on Retrieving & Saving Data. It includes an example of using a DataAdapter to retrieve and save data, with the ability to edit in between. That's basically what you're doing, with a bit of variation.
In your case, you can call FillSchema instead of Fill, because you don't actually want to retrieve any data. You also don't need the DELETE and UPDATE statements, because you're only inserting data.
Once you've got your DataTable, bind it to your grid via a BindingSource, e.g.
vb.net Code:
myBindingSource.DataSource = myDataTable
myDataGridView.DataSource = myBindingSource
When you want to add a new row, you use the BindingSource, e.g.
vb.net Code:
Dim newRow As DataRowView = myBindingSource.AddNew()
newRow("Column1") = Me.TextBox1.Text
newRow("Column2") = Me.TextBox2.Text
myBindingSource.EndEdit()
That's it, that's all.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|