March 29th, 2008, 10:47 AM
connect Visual Basic and Access 2003
I am trying to access a MS Access 2003 database from a Visual Basic project. I have written the following code in a module of the project. I call the dbOpen() function from some form code and then on another event I call the setAttracRecord() function, which causes an error.
I edited the code to try and track down the problem. When I execute the code, the msgbox saying "Reader DOES have rows." is displayed and then the GetString() method causes and error. I get the debug message "No data exists for the row/column.".
Private strConnect As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=database.mdb;Persist Security Info=False"
Private objConnect As New OleDbConnection(strConnect)
Sub setAttracRecord(ByVal s As String)
Dim strSQL As String = "SELECT * FROM tblAttrac"
Dim cmd As New OleDbCommand(strSQL, objConnect)
Dim dtRdr As OleDbDataReader
dtRdr = cmd.ExecuteReader
If dtRdr.HasRows Then
MsgBox("Reader DOES have rows.")
MsgBox("Reader does NOT have rows.")
'error occurs on next line
Dim strTest As String = dtRdr.GetString(0)
MsgBox("Returned:" & strTest)
I've tried to figure out this problem, on my own, but I've now run out of ideas. Because as far as I can tell dtRdr does have data in it, as HasRows() method returns true, but the debug message is telling me that it doesn't. Therefore, if anyone could help, I would very much appreciate it.
Thanks in advance,
By ThePreacher in forum Miscellaneous Security Discussions
Last Post: December 14th, 2006, 09:37 PM
By \/IP3R in forum AntiOnline's General Chit Chat
Last Post: March 7th, 2005, 10:25 PM
By gore in forum Operating Systems
Last Post: March 7th, 2004, 08:02 AM
By -DaRK-RaiDeR- in forum Newbie Security Questions
Last Post: December 14th, 2002, 08:38 PM
By Noble Hamlet in forum AntiOnline's General Chit Chat
Last Post: March 17th, 2002, 09:38 AM