|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
access dataError 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) -------------------------------------------------------- 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... 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. Show quote "feudalac!" <feuda***@gmail.com> wrote in message news:eg0c66$2cp$1@ss408.t-com.hr... > 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) > -------------------------------------------------------- > 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... So far, I worked with mysql, and nothing else....
So there are differences in sql ansi... thanks Norman Yuan wrote: Show quote > 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. > > > "feudalac!" <feuda***@gmail.com> wrote in message > news:eg0c66$2cp$1@ss408.t-com.hr... >> 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) >> -------------------------------------------------------- >> 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... > > -- 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... 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: Show quote > >> Public Function GetDataReader(ByVal AccessQuery As String) As AFTER YOU RETURN It and after you use it. do this.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() > >> AccessCommand = New System.Data.OleDb.OleDbCommand > >> AccessCommand.Connection = AccessConnection > >> AccessCommand.CommandText = AccessQuery > >> > >> AccessReader = AccessCommand.ExecuteReader()<--Error here > >> GetDataReader = AccessReader > >> Finally > >> End Try >> End Function 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 Show quote "feudalac!" <feuda***@gmail.com> wrote in message news:eg2a04$80o$1@ss408.t-com.hr... > So far, I worked with mysql, and nothing else.... > So there are differences in sql ansi... > > > > thanks > > > Norman Yuan wrote: > > 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. > > > > > > "feudalac!" <feuda***@gmail.com> wrote in message > > news:eg0c66$2cp$1@ss408.t-com.hr... > >> 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) > >> -------------------------------------------------------- > >> 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... > > > > > > > -- > 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 wrote:
> Use a pubs.mdb database (or northwind.mdb) and try simple selects like I know SQL well... i never used access before...> > "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. > .. 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.... > The code works fine as it is (it is copy+paste from my MySQL program)> Now, to your code. > > I know you can't .Close, and I think you can't .Dispose of an IDataReader > before using it. > as Norman said... there was a problem with my query... Thanks for help everyone Show quote > 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() >>>> AccessCommand = New System.Data.OleDb.OleDbCommand >>>> AccessCommand.Connection = AccessConnection >>>> AccessCommand.CommandText = AccessQuery >>>> >>>> AccessReader = AccessCommand.ExecuteReader()<--Error here >>>> 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 > > -- 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... |
|||||||||||||||||||||||