how to insert data from dataset into database

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2007
Posts: 1
Reputation: unknownunknown is an unknown quantity at this point 
Solved Threads: 0
unknownunknown unknownunknown is offline Offline
Newbie Poster

how to insert data from dataset into database

 
0
  #1
Feb 25th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 4
Reputation: luisofo is an unknown quantity at this point 
Solved Threads: 0
luisofo luisofo is offline Offline
Newbie Poster

Re: how to insert data from dataset into database

 
0
  #2
Feb 26th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 812
Reputation: arjunsasidharan is on a distinguished road 
Solved Threads: 13
arjunsasidharan's Avatar
arjunsasidharan arjunsasidharan is offline Offline
Practically a Posting Shark

Re: how to insert data from dataset into database

 
0
  #3
Feb 27th, 2007
Use have to use the SqlCommandBuilder to update the table in a database through dataset

Use this it may help:
  1. Dim object name as SqlCommandBuilder(DataAdapter's Name)
  2. DataAdapter's Name.Update(Datasetname, "Table Name")
There is just two ways to live your life.
One is as though nothing is a miracle.
The other is as if everything is.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC