c# - Access Type Mismatch -


having 2 tables:

mytable1:   id       autonumber   typecode text  mytable2   id      autonumber   pid     number   freq    number  using system.data.oledb; namespace accessselect {     class program     {         static void main(string[] args)         {             var sql = @"select 'x' mytable1 typecode=@typecode , exists (                         select 'x' mytable2 (freq=0 or freq=@freq) , mytable1.id=mytable2.pid)";              using (oledbconnection conn = new oledbconnection(@"provider=microsoft.jet.oledb.4.0;data source=gpi.mdb;jet oledb:database password=???"))             {                 conn.open();                 oledbcommand cmd = new oledbcommand(sql, conn);                  cmd.parameters.add(new oledbparameter("@typecode", "kk3000"));                 cmd.parameters.add(new oledbparameter("@freq", 50));                  var o = cmd.executescalar();             }         }     } } 

i keep getting exception 'data type mismatch in criteria expression.'

if change sql contain values:

select 'x' mytable1 typecode='kk3000' , exists (  select 'x' mytable2 (freq=0 or freq=50) ,  mytable1.id=mytable2.pid) 

i don't error....

any idea wrong?

from msdn:

the ole db .net provider not support named parameters passing parameters sql statement or stored procedure called oledbcommand when commandtype set text. in case, question mark (?) placeholder must used. example:

so change query to:

select 'x' mytable1 typecode = ?       , exists (select 'x' mytable2 (freq=0 or freq = ?) , mytable1.id=mytable2.pid) 

and have add parameters in same order occur in query.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -