Question Can anyone have a look at my code?

Adrian87

Member
Joined
Aug 13, 2009
Messages
13
Programming Experience
Beginner
Dim con As New OleDb.OleDbConnection


Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String

con.ConnectionString = "PROVIDER= Microsoft.Jet.OLEDB.4.0; Data
Source = D:\Adrian\Adrian1.mdb"

con.Open()

MsgBox("A Connection to the Database is now open")





sql = "SELECT * FROM tblStaffs"
da = New OleDb.OleDbDataAdapter(sql, con)

da.Fill(ds, " ") ---> got error with this code it show green color, what
wrong with it anyway? the name of the ds what should i put?
 
This is how the Fill method actually looks like:
VB.NET:
Public Overridable Function Fill ( _
    dataSet As DataSet _
) As Integer

and it returns the number of rows successfully added to or refreshed in the DataSet.

Means da.Fill(ds) will work for you? You may want to check out this link to see the Overload List.
 
what is wrong with my code?

MaxRows = ds.Tables("AddressBook").Rows.Count
inc = -1


txtFirstName.Text = ds.Tables("AddressBook").Rows(inc).Item(1)
txtLastName.Text = ds.Tables("AddressBook").Rows(inc).Item(2)
 
Dim con As New OleDb.OleDbConnection



con.ConnectionString = "PROVIDER= Microsoft.Jet.OLEDB.4.0; Data Source = D:\Adrian\Adrian1.mdb"

con.Open()

MsgBox("A Connection to the Database is now open")


Dim da As New OleDb.OleDbDataAdapter("Select * from Staffs", con)

Dim ds As New DataSet

da.Fill(ds, "AddressBook")

con.Close()



MaxRows = ds.Tables("AddressBook").Rows.Count
inc = -1




End Sub
Private Sub NavigateRecords()

txtFirstName.Text = ds.Tables("AddressBook").Rows(1).Item(1)
txtLastName.Text = ds.Tables("AddressBook").Rows(inc).Item(2)


End Sub


Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
If inc <> MaxRows - 1 Then
inc = inc + 1
NavigateRecords()
Else
MsgBox("No More Rows")
End If


End Sub

can anyone tell me what wrong? -1 ia not a valid index but i dun understand, even i change the number still cannot work? what wrong?
 
Back
Top