I have a oledb adapter linking table and a data table
this data table is the data source for a grid view
initially the data table will be empty obviously there will be no records in the table (data base)
then i merge a prepopulated data table with this empty data table and i can see the merged results in the grid view
when i trigger the update function .. these updates are not getting saved to the db,
but if i edit the grid view manually and write sme thng to it.. this time the same update function is called and the changes are saved..
BEFORE YOU READ FURTHER.. I HAVE NOT CALLED THE ACCEPT CHANGES METHOD.. JUST TO LET YOU KNOW
here is the code
THIS IS THE CODE WHICH MERGES THE TWO DATA SETS
Private Sub btnAddDefs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddDefs.Click
Dim dtDefClimate As New DataTable
'this code fetches the right default file form the database
Dim cmd1 As New OleDb.OleDbCommand("SELECT clim_name AS ClimateName, acronym AS Acronym, description AS Description FROM tbl_clim", conn)
Dim DA1 As New OleDb.OleDbDataAdapter(cmd1)
DA1.Fill(dtDefClimate)
conn.Close()
climDT.Merge(dtDefClimate, True)
btnAddDefs.Enabled = False
End Sub
THIS BLOCK CALLS THE UPDATE METHOD
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim myBuilder As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(DA)
Dim strsql1 As String = "INSERT INTO tbl_clim_userspec_child (id_clim_userspec_par, clim_name, clim_acronym, descr) " & _
"VALUES (@id_clim_userspec_par, @clim_name, @clim_acronym, @descr)"
Dim cmd1 As New OleDb.OleDbCommand(strsql1, conn)
DA.InsertCommand = cmd1
DA.InsertCommand.Parameters.Add("@id_clim_userspec_par", OleDb.OleDbType.BigInt, 40)
DA.InsertCommand.Parameters.Add("@clim_name", OleDb.OleDbType.Char, 35, "ClimateName")
DA.InsertCommand.Parameters.Add("@clim_acronym", OleDb.OleDbType.Char, 35, "Acronym")
DA.InsertCommand.Parameters.Add("descr", OleDb.OleDbType.Char, 35, "Description")
DA.InsertCommand.Parameters("@id_clim_userspec_par").Value = currID
Try
DA.Update(climDT)
Me.grdData.DataSource = climDT
Console.WriteLine(myBuilder.GetUpdateCommand().CommandText)
Console.WriteLine(myBuilder.GetDeleteCommand().CommandText)
btnSave.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
this data table is the data source for a grid view
initially the data table will be empty obviously there will be no records in the table (data base)
then i merge a prepopulated data table with this empty data table and i can see the merged results in the grid view
when i trigger the update function .. these updates are not getting saved to the db,
but if i edit the grid view manually and write sme thng to it.. this time the same update function is called and the changes are saved..
BEFORE YOU READ FURTHER.. I HAVE NOT CALLED THE ACCEPT CHANGES METHOD.. JUST TO LET YOU KNOW
here is the code
THIS IS THE CODE WHICH MERGES THE TWO DATA SETS
Private Sub btnAddDefs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddDefs.Click
Dim dtDefClimate As New DataTable
'this code fetches the right default file form the database
Dim cmd1 As New OleDb.OleDbCommand("SELECT clim_name AS ClimateName, acronym AS Acronym, description AS Description FROM tbl_clim", conn)
Dim DA1 As New OleDb.OleDbDataAdapter(cmd1)
DA1.Fill(dtDefClimate)
conn.Close()
climDT.Merge(dtDefClimate, True)
btnAddDefs.Enabled = False
End Sub
THIS BLOCK CALLS THE UPDATE METHOD
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim myBuilder As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(DA)
Dim strsql1 As String = "INSERT INTO tbl_clim_userspec_child (id_clim_userspec_par, clim_name, clim_acronym, descr) " & _
"VALUES (@id_clim_userspec_par, @clim_name, @clim_acronym, @descr)"
Dim cmd1 As New OleDb.OleDbCommand(strsql1, conn)
DA.InsertCommand = cmd1
DA.InsertCommand.Parameters.Add("@id_clim_userspec_par", OleDb.OleDbType.BigInt, 40)
DA.InsertCommand.Parameters.Add("@clim_name", OleDb.OleDbType.Char, 35, "ClimateName")
DA.InsertCommand.Parameters.Add("@clim_acronym", OleDb.OleDbType.Char, 35, "Acronym")
DA.InsertCommand.Parameters.Add("descr", OleDb.OleDbType.Char, 35, "Description")
DA.InsertCommand.Parameters("@id_clim_userspec_par").Value = currID
Try
DA.Update(climDT)
Me.grdData.DataSource = climDT
Console.WriteLine(myBuilder.GetUpdateCommand().CommandText)
Console.WriteLine(myBuilder.GetDeleteCommand().CommandText)
btnSave.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub