Help Deleting from DataBase

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hathan
    New Member
    • Dec 2007
    • 10

    #1

    Help Deleting from DataBase

    Can anyone explain why this code doesnt delete from the database. Some times it works and some times it errors i am confused.

    Code:
    Private Sub DeleteBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteBtn.Click
    
        Dim connStr As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source = G2G.mdb"
        Dim oDataTable As New DataTable
        Dim squlStr As String = "SELECT * From Staff"
        Dim oleDbStaffAdapter As New OleDb.OleDbDataAdapter(squlStr, connStr)
    
            oleDbStaffAdapter.Fill(oDataTable)
            Dim StaffDeleteRow As DataRow
    
            oDataTable.Rows.Item(Val(StaffnoTxt.Text)).Delete()
    
            Dim changes As Integer
            Dim commandbuilder As New OleDb.OleDbCommandBuilder(oleDbStaffAdapter)
    
            changes = oleDbStaffAdapter.Update(oDataTable)
    
    
        End Sub
    Thanks
  • hathan
    New Member
    • Dec 2007
    • 10

    #2
    An unhandled exception of type 'System.Data.Ol eDb.OleDbExcept ion' occurred in sy

    Hi i am getting An unhandled exception of type 'System.Data.Ol eDb.OleDbExcept ion' occurred in system.data.dll . Some times my code works and some times it doesn't. Its realy wierd. It is erroring on changes = oleDbStaffAdapt er.Update(aData Table) can anyone please help me.

    Code:
    Private Sub AddBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddBtn.Click
           
        Dim connStr As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source = G2G.mdb"
        Dim aDataTable As New DataTable
        Dim squlStr As String = "SELECT * From Staff"
        Dim oleDbStaffAdapter As New OleDb.OleDbDataAdapter(squlStr, connStr)
    
    
          Try
                aDataTable.Clear()
                StaffnoTxt.DataBindings.Clear()
                FnameTxt.DataBindings.Clear()
                LastnameTxt.DataBindings.Clear()
                NoTxt.DataBindings.Clear()
                PcodeTxt.DataBindings.Clear()
                DoornoTxt.DataBindings.Clear()
    
                oleDbStaffAdapter.Fill(aDataTable)
                Dim MyNewRow As DataRow = aDataTable.NewRow
    
                MyNewRow("Staff_No") = StaffnoTxt.Text
                MyNewRow("First_Name") = FnameTxt.Text
                MyNewRow("Surname") = LastnameTxt.Text
                MyNewRow("Tel_No") = NoTxt.Text
                MyNewRow("Post_Code") = PcodeTxt.Text
                MyNewRow("House") = DoornoTxt.Text
    
                aDataTable.Rows.Add(MyNewRow)
    
    
                Dim changes As Integer
                Dim commandbuilder As New OleDb.OleDbCommandBuilder(oleDbStaffAdapter)
                changes = oleDbStaffAdapter.Update(aDataTable)
    
                AddLbl.Text = "New Staff Added"
    
    
            Catch ex As InvalidOperationException
                MsgBox(ex.Message)
            End Try
    End Sub
    Thanks
    Jonathan

    Comment

    • kenobewan
      Recognized Expert Specialist
      • Dec 2006
      • 4871

      #3
      I thought it would have been commandbuilder. Update(aDataTab le), but its late and the screen has become blurred :).

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        I note the same code is coming up multiple question and that you are basically multiposting under the guise of different questions. I also find it difficult to believe that this is a university course, although some unis will offer anything if they can find a student.

        Your questions appears to be a Homework Assignment and you should make a proper attempt at assignment/program. This question will now be closed and you will have to post a new question when you're ready. I strongly recommend reading the posting guidelines.

        MODERATOR

        Comment

        Working...