Hi,

I have a requirement to insert data from dataset into a table in the database. Actually i have records in the excel sheet that has to be inserted into the database. I have populated them in a dataset. Now this dataset has to be validated against some conditions. After accepting the changes in the dataset . This table in the database has no records. Records in the dataset have to be inserted to that table. i dont know how to insert all the records in the dataset at one go... Please advice.

Thanks

Hello there: I have used this code in my application and it works. It is about populating the database with the information within a present form

Dim a As String = Me.ComboBox1.SelectedItem
Dim b As Integer = Me.txtDeel1.Text
Dim c As Integer = Me.txtDeel2.Text
Try
selectStr = "SELECT TbStukIDRegCD,TbStukIDDeel1,TbStukIDDeel2,TbStukCodeAanbieder," + _
"TbStukTijdInschrijving, TbStukCodeRectificatie, TbStukDatumVerlijden,TbStukAardStuk,TbStukDatumDoorhalingStuk," + _
"TbStukIndGeheelVerwerkt,TbStukReferentie,TbStukBedrag,TbStukCodeMeten,TbStukStukTekst FROM TbStuk"
da = New SqlDataAdapter(selectStr, conn)
da.Fill(Ds1, "TbStuk")
 
 
 
Dim TbStukRow As DataRow = Ds1.Tables("TbStuk").NewRow
''TbStukRow("TbStukDatumID") = Me.tdpdatum.Text
TbStukRow("TbStukIDRegCD") = Me.ComboBox1.SelectedItem
TbStukRow("TbStukIDDeel1") = Me.txtDeel1.Text
TbStukRow("TbStukIDDeel2") = Me.txtDeel2.Text
TbStukRow("TbStukCodeAanbieder") = Me.TextBox7.Text
TbStukRow("TbStukTijdInschrijving") = Me.TextBox6.Text
TbStukRow("TbStukCodeRectificatie") = Me.TextBox5.Text
TbStukRow("TbStukDatumVerlijden") = Me.DateTimePicker1.Text
TbStukRow("TbStukAardStuk") = Me.TextBox3.Text
TbStukRow("TbStukDatumDoorhalingStuk") = Me.DateTimePicker2.Text
TbStukRow("TbStukIndGeheelVerwerkt") = Me.TextBox1.Text
TbStukRow("TbStukReferentie") = Me.TextBox11.Text
TbStukRow("TbStukBedrag") = Me.TextBox10.Text
TbStukRow("TbStukCodeMeten") = Me.TextBox9.Text
TbStukRow("TbStukStukTekst") = Me.TextBox2.Text
Ds1.Tables("TbStuk").Rows.Add(TbStukRow)
Dim cmd As New SqlCommandBuilder(da)
da.Update(Ds1, "TbStuk")
'conn.Close()
Catch
Finally
MessageBox.Show("successfully inserted into database", "success info", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try

I do hope this can help you.

Use have to use the SqlCommandBuilder to update the table in a database through dataset

Use this it may help:

Dim object name as SqlCommandBuilder(DataAdapter's Name)
DataAdapter's Name.Update(Datasetname, "Table Name")
This article has been dead for over six months. Start a new discussion instead.