I have trouble updating my database. When I run my program and click on update database, I can then choose a record in my listbox, but when I click on save it button it goes to "Geen leidraad is Bygevoeg nie"
Here is my code (button update)
Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
'Edit Button to to edit my data in database
StatusLabel.Text = " Kies Leidraad om te verander"
If ListBox1.SelectedIndex <> -1 Then
SaveOrEdit = "Edit"
Else
StatusLabel.Text = " Geen bestaande leidraad is geselekteer nie, kies nou een om te verander"
End If
End Sub
My save button code
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
'button to save and edit databse
If SaveOrEdit = "Save" Then
Dim add As DialogResult
add = Cls_MessageBbox.Show("Is jy Seker jy will Leidraad" & vbCrLf & vbCrLf & TxtLuidraad.Text & vbCrLf & vbCrLf & "Byvoeg", "Byvoeg.", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If add = Windows.Forms.DialogResult.Yes Then
AddNew()
Else
StatusLabel.Text = "Geen leidraad is Bygevoeg nie"
End If
ElseIf SaveOrEdit = "Edit" Then
Edit()
Else
StatusLabel.Text = " Geen Leidraad is bygevoeg"
End If
End Sub
My update function
Public Function Edit() As String
'Function to edit my data
Try
Dim OleDbConn As OleDbConnection = New OleDbConnection(ConnString)
OleDbConn.Open()
Dim MyOledbCommand As OleDbCommand = New OleDbCommand()
Dim String1, String2, String3, String4, String5, string6, string7, string8, string9, string10, string11, string12, string13 As String
String1 = TxtLuidraad.Text
String2 = txtA1.Text()
String3 = txtA2.Text()
String4 = txtA3.Text()
String5 = txtA4.Text()
string6 = txtA5.Text()
string7 = txtA6.Text()
string8 = txtA7.Text()
string9 = txtA8.Text()
string10 = txtA9.Text()
string11 = txtA10.Text()
string12 = txtA11.Text()
string13 = txtA12.Text()
MyOledbCommand.CommandText = "UPDATE Tblokkies SET A1 = @string2, A2 = @string3, A3 = @string4, A4 = @string5, A5 = @string6, A6 = @string7, A7 = @string8, A8 = @string9, A9 = @string10, A10 = @string11, A11 = @string12, A12 = @string13 WHERE leidraad = @string1"
MyOledbCommand.Parameters.AddWithValue("@string1", Me.TxtLuidraad.Text)
MyOledbCommand.Parameters.AddWithValue("@string2", Me.txtA1.Text)
MyOledbCommand.Parameters.AddWithValue("@string3", Me.txtA2.Text)
MyOledbCommand.Parameters.AddWithValue("@string4", Me.txtA3.Text)
MyOledbCommand.Parameters.AddWithValue("@string5", Me.txtA4.Text)
MyOledbCommand.Parameters.AddWithValue("@string6", Me.txtA5.Text)
MyOledbCommand.Parameters.AddWithValue("@string7", Me.txtA6.Text)
MyOledbCommand.Parameters.AddWithValue("@string8", Me.txtA7.Text)
MyOledbCommand.Parameters.AddWithValue("@string9", Me.txtA8.Text)
MyOledbCommand.Parameters.AddWithValue("@string10", Me.txtA9.Text)
MyOledbCommand.Parameters.AddWithValue("@string11", Me.txtA10.Text)
MyOledbCommand.Parameters.AddWithValue("@string12", Me.txtA11.Text)
MyOledbCommand.Parameters.AddWithValue("@string13", Me.txtA12.Text)
MyOledbCommand.Connection = OleDbConn
MyOledbCommand.ExecuteNonQuery()
OleDbConn.Close()
DisableTextboxes()
NeroBar1.Value = 0
FillDataGrid("Select * from Tblokkies")
FillListBox("Select * from Tblokkies")
btnaddNew.Enabled = True
btnDelete.Enabled = True
' btnupdate.Enabled = True
SaveOrEdit = "Cancel"
'StatusLabel.Text = " Inligtin Verander."
StatusLabel.Text = "Leidraad :" & TxtLuidraad.Text & ": Verander."
Catch err As System.Exception
StatusLabel.Text = err.Message
End Try
End Function