Unable to update

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hendrikbez
    New Member
    • May 2009
    • 7

    Unable to update

    I really need help on this, I just can not get the Update/edit correct on this form,

    I can add new/delete info to data, but cannot update/edit, I have tryd everything that I could, but no luck on my side, I have put txt file of my page.

    Is their a other way to do this then

    Can anyone please help me out!!!!!!
    Attached Files
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    Hi hendrikbez,
    Welcome to Bytes...When you wish to provide code, its better if you post code that is relevant to the problem. Posting the entire form code is not going help (most of time )...
    How are you updating/ editing the record? Are you using database?

    Comment

    • hendrikbez
      New Member
      • May 2009
      • 7

      #3
      Yes I am using access 2003 as a database.

      I can add and delete, not update, I did give al ther code for that page, as I don't know were my probel is.

      Comment

      • PRR
        Recognized Expert Contributor
        • Dec 2007
        • 750

        #4
        Check whether your query works (for update) ... with sample values ....

        Comment

        • hendrikbez
          New Member
          • May 2009
          • 7

          #5
          I think the problem is in my vb.net code, I can add and delete and update my database manualy. Here are my code for update.

          It seems that it does not sse my function
          Code:
            Public Function Edit() As Boolean
          
                  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()
          
                      FillDataGrid("Select * from Tblokkies")
                      FillListBox1("Select * from Tblokkies")
                      FillListBox2("Select * from Tblokkies")
                      TxtLuidraad.Enabled = False
                      txtA1.Enabled = False
                      txtA2.Enabled = False
                      txtA3.Enabled = False
                      txtA4.Enabled = False
                      txtA5.Enabled = False
                      txtA6.Enabled = False
                      txtA7.Enabled = False
                      txtA8.Enabled = False
                      txtA9.Enabled = False
                      txtA10.Enabled = False
                      txtA11.Enabled = False
                      txtA12.Enabled = False
          
                      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
          Code:
            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
          
                  EnableTextboxes(True)
                  TxtLuidraad.Enabled = True
                  txtA1.Enabled = True
                  txtA2.Enabled = True
                  txtA3.Enabled = True
                  txtA4.Enabled = True
                  txtA5.Enabled = True
                  txtA6.Enabled = True
                  txtA7.Enabled = True
                  txtA8.Enabled = True
                  txtA9.Enabled = True
                  txtA10.Enabled = True
                  txtA11.Enabled = True
                  txtA12.Enabled = True
          
              End Sub
          Code:
           Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
          
                  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
          
                          ListBox1.Text = "Geen leidraad is Bygevoeg nie"
          
                      End If
          
          
                  ElseIf SaveOrEdit = "Edit" Then
                      Edit()
                      'If Edit() = True Then
                      'MessageBox.Show("Leidraad is verander")
                      'Else
                      'StatusLabel.Text = " Die Leidraad is nie verander nie"
                      'End If
                  Else
                      StatusLabel.Text = " Geen Leidraad is bygevoeg"
                  End If
              End Sub

          Comment

          • PRR
            Recognized Expert Contributor
            • Dec 2007
            • 750

            #6
            Debug your program... and copy the query... check whether all values are right... specially the update check... (where clause)

            Comment

            Working...