access data

F

feudalac!

Why isn't this working? (it works in my other program...)

Error is:
Data type mismatch in criteria expression


public DatabasePath As String

Public Function GetDataReader(ByVal AccessQuery As String) As
System.Data.OleDb.OleDbDataReader
Dim AccessConnection As System.Data.OleDb.OleDbConnection
Dim AccessCommand As System.Data.OleDb.OleDbCommand
Dim AccessReader As System.Data.OleDb.OleDbDataReader
Try
AccessConnection = New System.Data.OleDb.OleDbConnection
AccessConnection.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DatabasePath & ";User
Id=;Password=;"
AccessConnection.Open()
Try
AccessCommand = New System.Data.OleDb.OleDbCommand
AccessCommand.Connection = AccessConnection
AccessCommand.CommandText = AccessQuery

AccessReader = AccessCommand.ExecuteReader()<--Error here
GetDataReader = AccessReader

Catch MyError As System.Data.OleDb.OleDbException
MsgBox(MyError.Message, MsgBoxStyle.Critical, "Error.")
End Try
Catch MyError As System.Data.OleDb.OleDbException
MsgBox(MyError.Message, MsgBoxStyle.Critical, "Error.")
Finally
AccessCommand.Dispose()
End Try
End Function




thanks




--
You're not paid to think. A mindless worker is a happy worker. Shut up
and do your job!
- Tata Feudalac!

Certified Social Engineering Specialist (Because there is no patch for
human stupidity)
 
N

Norman Yuan

As the error indicates, something is wrong in the SQL statement (i.e. the
value of AccessQuery string variable). So, you need to check that, instead
of the code you showed.
 
F

feudalac!

So far, I worked with mysql, and nothing else....
So there are differences in sql ansi...



thanks


Norman said:
As the error indicates, something is wrong in the SQL statement (i.e. the
value of AccessQuery string variable). So, you need to check that, instead
of the code you showed.


--
You're not paid to think. A mindless worker is a happy worker. Shut up
and do your job!
- Tata Feudalac!

Certified Social Engineering Specialist (Because there is no patch for
human stupidity)
 
S

sloan

Use a pubs.mdb database (or northwind.mdb) and try simple selects like

"Select * from authors" or "Select * from Orders"

DO "Select * " ONLY AS A TEST... DON"T LeAVE IT THAT WAY.

Get the simple thing working first, then move on to more advanced queries.
...

Now, to your code.

I know you can't .Close, and I think you can't .Dispose of an IDataReader
before using it.

Change your code to:


AFTER YOU RETURN It and after you use it. do this.

sub ProcWhichCallsTheAboveProc

dim idr as IDataReader

''idr as IDataReader
try

idr = new DAL().GetDataReader("Select * from authors")

'' use the IDataReader

finally
if not ( idr is nothing) then
idr.Close()
end if

end try
 
F

feudalac!

sloan said:
Use a pubs.mdb database (or northwind.mdb) and try simple selects like

"Select * from authors" or "Select * from Orders"

DO "Select * " ONLY AS A TEST... DON"T LeAVE IT THAT WAY.

Get the simple thing working first, then move on to more advanced queries.
..
I know SQL well... i never used access before...

in MySQL it is : WHERE field_name='value'

in Access it is : WHERE (((field_name)=value))

i didn't know there were theese differences in sql ansi....


Now, to your code.

I know you can't .Close, and I think you can't .Dispose of an IDataReader
before using it.
The code works fine as it is (it is copy+paste from my MySQL program)


as Norman said... there was a problem with my query...




Thanks for help everyone
Change your code to:



AFTER YOU RETURN It and after you use it. do this.

sub ProcWhichCallsTheAboveProc

dim idr as IDataReader

''idr as IDataReader
try

idr = new DAL().GetDataReader("Select * from authors")

'' use the IDataReader

finally
if not ( idr is nothing) then
idr.Close()
end if

end try



--
You're not paid to think. A mindless worker is a happy worker. Shut up
and do your job!
- Tata Feudalac!

Certified Social Engineering Specialist (Because there is no patch for
human stupidity)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top