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
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:
Quote:
So, the data is NOT going to be saved to a database?
and you said:
Quote:
yes you are correct.
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.......
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.
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 ?
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 ?
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.
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.