Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2006

Tip: Looking for answers? Try searching our database.

access data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
feudalac! - 04 Oct 2006 14:20 GMT
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

Signature

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)
--------------------------------------------------------
http://www.fotozine.org/index.php?stranica=clan&uid=1352
http://www.thinkgeek.com/brain/gimme.cgi?wid=81d35dc8f
http://groups.google.com/group/fejkneraddangub
http://capetans.bloger.hr
--------------------------------------------------------
I was young, I need gold pieces...

Norman Yuan - 04 Oct 2006 15:14 GMT
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.

> Why isn't this working? (it works in my other program...)
>
[quoted text clipped - 33 lines]
>
> thanks
feudalac! - 05 Oct 2006 07:59 GMT
So far, I worked with mysql, and nothing else....
So there are differences in sql ansi...

thanks

> 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
[quoted text clipped - 37 lines]
>>
>> thanks

Signature

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)
--------------------------------------------------------
http://www.fotozine.org/index.php?stranica=clan&uid=1352
http://www.thinkgeek.com/brain/gimme.cgi?wid=81d35dc8f
http://groups.google.com/group/fejkneraddangub
http://capetans.bloger.hr
--------------------------------------------------------
I was young, I need gold pieces...

sloan - 05 Oct 2006 13:31 GMT
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:

> >> Public Function GetDataReader(ByVal AccessQuery As String) As
IDataReader
> >>     Dim AccessConnection As System.Data.OleDb.OleDbConnection
> >>     Dim AccessCommand As System.Data.OleDb.OleDbCommand
> >>     Dim AccessReader As System.Data.OleDb.OleDbDataReader

> >>         Try
> >>         AccessConnection.Open()
[quoted text clipped - 5 lines]
> >>             GetDataReader = AccessReader
> >>     Finally

> >>     End Try
>> End Function

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

> So far, I worked with mysql, and nothing else....
> So there are differences in sql ansi...
[quoted text clipped - 42 lines]
> >>
> >> thanks
feudalac! - 06 Oct 2006 08:05 GMT
> Use a pubs.mdb database (or northwind.mdb) and try simple selects like
>
[quoted text clipped - 4 lines]
> 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:
>
[quoted text clipped - 36 lines]
>
> end try

Signature

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)
--------------------------------------------------------
http://www.fotozine.org/index.php?stranica=clan&uid=1352
http://www.thinkgeek.com/brain/gimme.cgi?wid=81d35dc8f
http://groups.google.com/group/fejkneraddangub
http://capetans.bloger.hr
--------------------------------------------------------
I was young, I need gold pieces...


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.