On a form I have several text boxes binded to a bindingsource and including a datagridview.
I have populated the textboxes with database fields successfully and the datagridview displays the correct information.
I have the following code to save the information to the database but I cannot get it to work.
Private Sub SaveRecordData()
dS.Tables("Recipe".Rows(RecipeBindingSource.Position).Item("Title") = txtTitle.Text
dS.Tables("Recipe").Rows(RecipeBindingSource.Position).Item("Notes") = txtNotes.Rtf
adapter.Update(dS, "Recipe")
end sub
I have made the ds (dataset) and adapter global variables and were used when I filled the database.
Sub FillDatabase()
ConnectionString = gINI(iniFile, "Settings", "ConnectionString", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\RECIPE.MDB")
Me.RecipeTableAdapter.Fill(Me.recipedataset1.Recipe)
Dim sQuery As String = ""
Try
If RN = 0 Then
sQuery = "SELECT * FROM [RECIPE] ORDER BY [TITLE], [CATEGORY]"
Else
sQuery = "SELECT * FROM [RECIPE] WHERE [USERID]=" & RN & " ORDER BY [TITLE], [CATEGORY]"
End If
Dim adapter As New OleDb.OleDbDataAdapter(sQuery, Connection)
dS = New DataSet()
dS.Tables.Add("Recipes")
adapter.Fill(dS, "Recipe")
Me.RecipeBindingSource.DataMember = "Recipe"
Me.RecipeBindingSource.DataSource = dS
Connection.Close()
BindData() e.g. txtTitle.DataBindings.Add(New System.Windows.Forms.Binding("Text", RecipeBindingSource, "Title", True))
End Sub
I have tried many code examples here in order to save the data, none of which has worked.
Can anyone please help me with this?