how to save a dataset back to the database

G

Guest

greetings,

i've manually created a dataset which contains data input from users. i
validate the dataset against the business logic and once everything is done,
i would like to save the values in the dataset into the database. the
database has 5 columns and so does my dataset. my dataset has all the same
name field name and datatype as the database. is there a possibility to merge
the dataset in to the database?

i was hoping there would be a way so that i can avoid loop insert. insert
row by row into the database. thanks for help me out..
 
J

Jos

Asha said:
greetings,

i've manually created a dataset which contains data input from users.
i validate the dataset against the business logic and once everything
is done, i would like to save the values in the dataset into the
database. the database has 5 columns and so does my dataset. my
dataset has all the same name field name and datatype as the
database. is there a possibility to merge the dataset in to the
database?

i was hoping there would be a way so that i can avoid loop insert.
insert row by row into the database. thanks for help me out..

Use the Update method on the DataAdapter:

Dim conn As New OleDbConnection(strConn)
Try
conn.Open()
' fill dataset from the database
Dim da As New OleDbDataAdapter(strSQL,conn)
Dim ds As New DataSet()
da.Fill(ds)

' do your stuff with the DataSet here

Dim cb As New OleDbCommandBuilder(da)
' update the database with the dataset
da.Update(ds)
Catch ex As Exception
lblError.Text=ex.Message
Finally
conn.Close()
End Try
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top