why my database only return an empty row

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • roseate4amor
    New Member
    • Aug 2008
    • 1

    why my database only return an empty row

    dear all,

    i have a problem that i try to fix since the last few weeks.
    i need to add a new data in microsoft office database using dataset in visual basic.
    the problem is, when i insert new data and press the commit button they say new record added to database. however when i check my database, they only insert an empty row with none of data that i type is in. here is my code... i really u guys can help me.

    Imports System.Data

    Public Class New_Passenger

    Dim con As New OleDb.OleDbConn ection
    Dim ds2 As New DataSet
    Dim da2 As OleDb.OleDbData Adapter
    Dim sql As String
    Dim ds2NewRow As DataRow
    Dim inc As Integer
    Dim maxrows As Integer



    Private Sub frmResults_Load (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
    con.ConnectionS tring = "PROVIDER = Microsoft.Jet.O leDB.4.0;Data Source = C:\Users\Ms.Con fuse\Desktop\bo oksaflights.mdb "
    con.Open()

    sql = "SELECT * FROM Passengers"
    da2 = New OleDb.OleDbData Adapter(sql, con)

    da2.Fill(ds2, "Passengers ")
    da2.Update(ds2, "Passengers ")
    con.Close()

    End Sub
    Private Sub NavigateRecords ()
    Dim cb As New OleDb.OleDbComm andBuilder(da2)
    txtID.Text = ds2.Tables("Pas sengers").Rows( inc).Item(0)
    txtName.Text = ds2.Tables("Pas sengers").Rows( inc).Item(1)
    txtInitials.Tex t = ds2.Tables("Pas sengers").Rows( inc).Item(2)
    da2.Update(ds2, "Passengers ")
    MsgBox("Data updated")


    End Sub


    Private Sub btnAdd_Click(By Val sender As System.Object, ByVal e As System.EventArg s) Handles btnAdd.Click
    btnCommit.Enabl ed = True
    btnAdd.Enabled = False
    txtID.Clear()
    txtName.Clear()
    txtInitials.Cle ar()

    End Sub

    Private Sub btnCommit_Click (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnCommit.Click

    Dim cb As New OleDb.OleDbComm andBuilder(da2)
    Dim ds2NewRow As DataRow
    Dim CommandText As OleDb.OleDbComm and

    If inc <> -1 Then

    ds2NewRow = ds2.Tables("Pas sengers").NewRo w()
    ds2NewRow.Item( "PassengerI D") = txtID.Text.ToSt ring
    ds2NewRow.Item( "Name") = txtName.Text.To String
    ds2NewRow.Item( "Initials") = txtInitials.Tex t.ToString

    ds2NewRow.Item( 0) = txtID.Text
    ds2NewRow.Item( 1) = txtName.Text
    ds2NewRow.Item( 2) = txtInitials.Tex t

    ds2.Tables("Pas sengers").Rows. Add(ds2NewRow)
    da2.Update(ds2, "Passengers ")

    CommandText = New OleDb.OleDbComm and(sql, con)
    MsgBox("New Record added to the Database")

    btnCommit.Enabl ed = False
    btnAdd.Enabled = True
    btnUpdate.Enabl ed = True

    Else
    MsgBox("Failed to add in new flights Record. Please try again.", MsgBoxStyle.Exc lamation)

    End If

    End Sub

    Private Sub btnUpdate_Click (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnUpdate.Click

    ds2.Tables("Pas sengers").Rows( inc).Item(0) = txtID.Text
    ds2.Tables("Pas sengers").Rows( inc).Item(1) = txtName.Text
    ds2.Tables("Pas sengers").Rows( inc).Item(2) = txtInitials.Tex t
    MsgBox("Data updated")
    End Sub
    End Class
Working...