|
-
August 4th, 2005, 12:30 AM
#1
Need to retreive all 500 rows from a table
When i query the database to show all rows in a table, I only get "1 of 1" on my binding navigator and the navigation arrows are disabled. There's supposed to be over 500 records. I've checked the table name and passwords. Anyone know why this is happening?
Access database version: 2000, can't upgrade either.
Using vb.net 2005 express
Here's the code:
Code:
Imports System.Data.Oledb
Imports System.Windows.Forms
Module modLeads
Public mystr As String
Public myDS As DataSet
Public myDA As OleDbDataAdapter
Public ConnString As String
Public connection As OleDbConnection
Public sUser As String 'user name
Public sAccountType As String 'account type
Public sAppPath As String 'location of the application
Public sFormName As String 'form name
Public leadsBinding As New BindingSource()
End Module
Code:
Imports System.Data.Oledb
Imports System.Windows.Forms
Public Class frmLeadsView
Private Sub frmLeadsView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'open the database to begin looking for information
On Error GoTo nodb
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sAppPath & "\master.mdb;Persist Security Info=False;Jet OLEDB:Database Password=******"
connection = New OleDb.OleDbConnection
connection.ConnectionString = ConnString
connection.Open()
'create the appropriate search string and search
On Error GoTo badsql
mystr = "SELECT * from leads"
myDA = New OleDbDataAdapter(mystr, connection)
myDS = New DataSet
myDA.Fill(myDS, "leads")
connection.Close()
On Error GoTo showerror
bnvLeads.BindingSource = leadsBinding
leadsBinding.DataSource = myDS
lblName1.DataBindings.Add(New Binding("text", leadsBinding, "name1", False))
nodb:
'caught a databse error: couldn't find the database file
MsgBox("Unable to find database. Please see system administrator. " & My.Application.Info.DirectoryPath & "\employee.mdb", MsgBoxStyle.Critical, sFormName)
'get out of the sub to prevent further errors..
Exit Sub
badsql:
'caught a problem with the sql statement!
MsgBox("Unable to query database. Please see system administrator. " & Chr(10) & "Error Numer: " & Err.Number & Chr(10) & "Description: " & Err.Description & Chr(10) & mystr, MsgBoxStyle.Critical, sFormName)
'get out of the sub to prevent further errors...
Exit Sub
showerror:
MsgBox("General error. Please see system administrator. " & Chr(10) & "Error Numer: " & Err.Number & Chr(10) & "Description: " & Err.Description, MsgBoxStyle.Critical, sFormName)
End Sub
End Class
-
August 4th, 2005, 07:22 AM
#2
Re: Need to retreive all 500 rows from a table
DO NOT DO THIS
On Error GoTo badsql
nodb:
badsql:
showerror:
Do something like this instead
Code:
TRY
Your code
CATCH ex as Oledb.oledbexception
'do your stuff here depending on the kind of exception
CATCH ex as Exception
'Do stuff here this catches all exception that aren'T listed up.
ENd try
Nicolas Bohemier
-
August 4th, 2005, 09:05 AM
#3
Re: Need to retreive all 500 rows from a table
Check how many records are added into the DataSet with the Fill method. If that is 1 too.. then I guess something is wrong with the table..there may not be enough records. Are you getting any exceptions? The query seems to be alright. And there must not be anything wrong with the connection because atleast it returns 1 row. Is this 1 row a valid row..check for it. I would suggest running the query directly with Access. Use the exception handling as suggested by Boumxyz2. Debug well to see whats happening at each stage of the code. Hope this helps. Good Luck.
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|