I would like to add a new record to a table. I have open the database, however, I can not workout how the add the new data to the dateSet. Eg. I have field name in the table call ‘Mean Temperture’, how do I add a new value like ‘1.2’. This is the code I am trying:
Any help would be great.
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\...\Porter Heights Weather Data.mdb;"
Using connection As New OleDbConnection(connectionString)
Dim adapter As New OleDbDataAdapter()
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(adapter)
connection.Open()
Dim dataSet As DataSet = New DataSet
adapter.Fill(dataSet, "Weather Data")
adapter.Update(dataSet, "Weather Data")
connection.Close()
End Using
OleDB - Adding a new record to a table
prashantguptak
Hi,
Please check the below link and it should help you add a new record.
Link: http://msdn2.microsoft.com/en-us/library/5ycd1034(VS.80).aspx
Thank you,
Bhanu.
GMSherif
Try adding the following code...
Dim dr as Datarow = dataset.Tables(0).NewRow()
dr(0) = 1.2
I'm not sure if there are errors in the code... just debug it when an exception appears, I just typed it here directly.
HTH,