SQL (Access)- Catch Error MSG

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I am trying to access a row of data from an Access database based on info
entered into a textbox.

I "int.Parse" the textbox name so that I could use it in the "WHERE"
criteria, but I keep getting this error msg: "Data type mismatch in criteria
expression".

All the fields in the data table are "number" fields.

Can anyone give me any sugguestions?
Here's the the partial code:

int TotWageFld = int.Parse(txtTotWage.Text);

daDataAdapter=
new OleDbDataAdapter("SELECT * FROM StateTax " +
"WHERE fldLowerLimit <= '" +
TotWageFld +
"'AND " + "fldUpperLimit <= '" +
TotWageFld +
"'",cnADONetConnection);

Help,
CsharpNewcommer
 
Hi,

Is there any reason that you first create an integer from your textbox
string and than try to use it as a not casted string in your Select
statement?

Cor
 
¤ Hi
¤ I am trying to access a row of data from an Access database based on info
¤ entered into a textbox.
¤
¤ I "int.Parse" the textbox name so that I could use it in the "WHERE"
¤ criteria, but I keep getting this error msg: "Data type mismatch in criteria
¤ expression".
¤
¤ All the fields in the data table are "number" fields.
¤
¤ Can anyone give me any sugguestions?
¤ Here's the the partial code:
¤
¤ int TotWageFld = int.Parse(txtTotWage.Text);
¤
¤ daDataAdapter=
¤ new OleDbDataAdapter("SELECT * FROM StateTax " +
¤ "WHERE fldLowerLimit <= '" +
¤ TotWageFld +
¤ "'AND " + "fldUpperLimit <= '" +
¤ TotWageFld +
¤ "'",cnADONetConnection);
¤
¤ Help,
¤ CsharpNewcommer

If your database columns are numeric then do not enclose the criteria from your WHERE statement in
single quotes.

You can also use an Access parameterized QueryDef to avoid these types of syntax issues.


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Hi Cor,

The reason is probably inexperience and the fact that I'm pretty much
teaching myself C# and getting more exposure to SQL. I am trying to write a
small payroll application for a friend, but I am using a test program to
experiment with the DB bits.
 
Hi Paul,

Thanks for your help. I will try your advice.
Also you suggested using an "Access parameterized QueryDef". Where can I
find more info on the topic?
 
¤ Hi Paul,
¤
¤ Thanks for your help. I will try your advice.
¤ Also you suggested using an "Access parameterized QueryDef". Where can I
¤ find more info on the topic?
¤

If you have Microsoft Access you can easily create queries using parameters and save them to the
database. The below link has an example the uses ADO.NET to execute an Access parameterized
QueryDef.

http://makeashorterlink.com/?I1FB26ACB


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Back
Top