Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 30th, 2008, 04:26 AM
Newbie
 
Join Date: Aug 2008
Posts: 1
Default 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.OleDbConnection
Dim ds2 As New DataSet
Dim da2 As OleDb.OleDbDataAdapter
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.EventArgs) Handles MyBase.Load
con.ConnectionString = "PROVIDER = Microsoft.Jet.OleDB.4.0;Data Source = C:\Users\Ms.Confuse\Desktop\booksaflights.mdb"
con.Open()

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

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

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


End Sub


Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
btnCommit.Enabled = True
btnAdd.Enabled = False
txtID.Clear()
txtName.Clear()
txtInitials.Clear()

End Sub

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

Dim cb As New OleDb.OleDbCommandBuilder(da2)
Dim ds2NewRow As DataRow
Dim CommandText As OleDb.OleDbCommand

If inc <> -1 Then

ds2NewRow = ds2.Tables("Passengers").NewRow()
ds2NewRow.Item("PassengerID") = txtID.Text.ToString
ds2NewRow.Item("Name") = txtName.Text.ToString
ds2NewRow.Item("Initials") = txtInitials.Text.ToString

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

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

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

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

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

End If

End Sub

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

ds2.Tables("Passengers").Rows(inc).Item(0) = txtID.Text
ds2.Tables("Passengers").Rows(inc).Item(1) = txtName.Text
ds2.Tables("Passengers").Rows(inc).Item(2) = txtInitials.Text
MsgBox("Data updated")
End Sub
End Class
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles