Why can't I update all the fields in my database via vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vonn
    New Member
    • Sep 2010
    • 1

    Why can't I update all the fields in my database via vb.net

    There are 4 fields in my database(exlcud ing the primary key)...only 3 fields can be successfully updated. the "Section" field returns an error pointing to da.Update(ds, "moreforenginee rs")?

    the following is my code

    Public Class Register
    Dim cb As New OleDb.OleDbComm andBuilder(da)
    Dim dsNewRow As DataRow
    Dim inc As Integer
    Dim MaxRows As Integer
    Dim con As New OleDb.OleDbConn ection
    Dim dbProvider As String
    Dim dbSource As String
    Dim ds As New DataSet
    Dim da As OleDb.OleDbData Adapter
    Dim sql As String
    Private Sub NavigateRecords ()
    SectionTextBox. Text = ds.Tables("more forengineers"). Rows(inc).Item( "Section")
    LastNameTextBox .Text = ds.Tables("more forengineers"). Rows(inc).Item( "LName")
    FirstNameTextBo x.Text = ds.Tables("more forengineers"). Rows(inc).Item( "FName")
    MobileNoTextBox .Text = ds.Tables("more forengineers"). Rows(inc).Item( "MobileNo")
    End Sub
    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
    'TODO: This line of code loads data into the 'Moreforenginee rsDataSet.Regis ter' table. You can move, or remove it, as needed.

    ClearButton.Ena bled = False
    RegisterButton. Enabled = False

    loaddb()

    End Sub
    Private Sub loaddb()
    con.Close()
    Me.RegisterTabl eAdapter.Fill(M e.Moreforengine ersDataSet.Regi ster)

    dbProvider = "PROVIDER=Micro soft.Jet.OLEDB. 4.0;"
    dbSource = "Data Source = C:\Users\Gerald ine\Documents\V isual Studio 2010\Projects\m oreforengineers \moreforenginee rs\moreforengin eers.mdb"

    con.ConnectionS tring = dbProvider & dbSource
    con.Open()


    sql = "SELECT * FROM Register"
    da = New OleDb.OleDbData Adapter(sql, con)
    da.Fill(ds, "moreforenginee rs")

    inc = 0
    NavigateRecords ()

    con.Close()

    MaxRows = ds.Tables("more forengineers"). Rows.Count

    End Sub


    Private Sub RegisterButton_ Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles RegisterButton. Click
    RegisterButton. Enabled = True
    AddButton.Enabl ed = False
    UpdateButton.En abled = False
    DeleteButton.En abled = False

    If inc <> -1 Then

    Dim cb As New OleDb.OleDbComm andBuilder(da)
    Dim dsNewRow As DataRow

    dsNewRow = ds.Tables("more forengineers"). NewRow()
    dsNewRow.Item(" Section") = SectionTextBox. Text
    dsNewRow.Item(" LName") = LastNameTextBox .Text
    dsNewRow.Item(" FName") = FirstNameTextBo x.Text
    dsNewRow.Item(" MobileNo") = MobileNoTextBox .Text

    ds.Tables("more forengineers"). Rows.Add(dsNewR ow)
    loaddb()
    da.Update(ds, "moreforenginee rs")

    MsgBox("New Record added to the Database")

    AddButton.Enabl ed = True
    UpdateButton.En abled = True
    DeleteButton.En abled = True
    CancelButton.En abled = True

    End If
    End Sub

    Private Sub ClearButton_Cli ck(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ClearButton.Cli ck
    SectionTextBox. Clear()
    FirstNameTextBo x.Clear()
    LastNameTextBox .Clear()
    MobileNoTextBox .Clear()
    End Sub


    Private Sub NextButton_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles NextButton.Clic k
    If inc <> MaxRows - 1 Then
    inc = inc + 1
    NavigateRecords ()
    Else
    MsgBox("No More Rows")
    End If
    End Sub

    Private Sub PreviousButton_ Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles PreviousButton. Click
    If inc > 0 Then
    inc = inc - 1
    NavigateRecords ()
    ElseIf inc = -1 Then
    MsgBox("No Records Yet")
    ElseIf inc = 0 Then
    MsgBox("First Record")
    End If

    End Sub

    Private Sub LastButton_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles LastButton.Clic k
    If inc <> MaxRows - 1 Then
    inc = MaxRows - 1
    NavigateRecords ()
    End If
    End Sub

    Private Sub FirstButton_Cli ck(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles FirstButton.Cli ck
    If inc <> 0 Then
    inc = 0
    NavigateRecords ()
    End If

    End Sub

    Private Sub RegisterBinding NavigatorSaveIt em_Click(ByVal sender As System.Object, ByVal e As System.EventArg s)
    Me.Validate()
    Me.RegisterBind ingSource.EndEd it()
    Me.TableAdapter Manager.UpdateA ll(Me.Moreforen gineersDataSet)

    End Sub

    Private Sub UpdateButton_Cl ick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles UpdateButton.Cl ick
    Dim cb As New OleDb.OleDbComm andBuilder(da)


    ds.Tables("more forengineers"). Rows(inc).Item( "Section") = SectionTextBox. Text
    ds.Tables("more forengineers"). Rows(inc).Item( "LName") = LastNameTextBox .Text
    ds.Tables("more forengineers"). Rows(inc).Item( "FName") = FirstNameTextBo x.Text
    ds.Tables("more forengineers"). Rows(inc).Item( "MobileNo") = MobileNoTextBox .Text

    da.Update(ds, "moreforenginee rs")

    MsgBox("Data updated")

    loaddb()

    End Sub

    Private Sub AddButton_Click (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles AddButton.Click
    RegisterButton. Enabled = True
    AddButton.Enabl ed = False
    UpdateButton.En abled = False
    DeleteButton.En abled = False
    ClearButton.Ena bled = True

    SectionTextBox. Clear()
    FirstNameTextBo x.Clear()
    LastNameTextBox .Clear()
    MobileNoTextBox .Clear()

    End Sub

    Private Sub CancelButton_Cl ick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles CancelButton.Cl ick
    RegisterButton. Enabled = False
    AddButton.Enabl ed = True
    UpdateButton.En abled = True
    DeleteButton.En abled = True
    ClearButton.Ena bled = False
    CancelButton.En abled = False

    inc = 0
    NavigateRecords ()

    End Sub

    Private Sub DeleteButton_Cl ick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles DeleteButton.Cl ick
    Dim cb As New OleDb.OleDbComm andBuilder(da)

    If MessageBox.Show ("Do you really want to Delete this Record?", "Delete", MessageBoxButto ns.YesNo, MessageBoxIcon. Warning) = DialogResult.No Then

    MsgBox("Operati on Cancelled")
    Exit Sub

    Else


    ds.Tables("more forengineers"). Rows(inc).Delet e()
    MaxRows = MaxRows - 1

    inc = 0
    loaddb()
    da.Update(ds, "moreforenginee rs")

    End If

    End Sub
    End Class
  • mzmishra
    Recognized Expert Contributor
    • Aug 2007
    • 390

    #2
    What exception or error you are getting

    Comment

    Working...