简体   繁体   English

条件表达式中的数据类型不匹配

[英]Data type mismatch in criteria expression

I am trying to populate a Dataset based on a specific Selection ID but get the error 我正在尝试基于特定的选择ID填充数据集,但出现错误

Data type mismatch in criteria expression.

Not exactly sure why I have this error. 不完全确定为什么我有此错误。

conn = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;
                                Data Source =" + Server.MapPath("App_Data\\HarryPothead.mdb"));
        conn.Open();

        DataSet ds = new DataSet();

        OleDbDataAdapter dba = new OleDbDataAdapter("SELECT * FROM [Person] WHERE [StatusIdFrn] = '" + statusID + "'", conn);
        dba.Fill(ds, "PersonName");
        DataTable dt = ds.Tables["PersonName"];

        drpPerson.DataSource = ds.Tables[0];
        drpPerson.DataTextField = "PersonName";
        drpPerson.DataBind();

        conn.Close();

Advice perhaps on how to overcome this. 关于如何克服这一问题的建议。

The databsase I am Selecting from is an Access database and the table I am selecting from three fields, PersonId which is of the type AutoNumber, PersonName which is of the type Text and StatusIdFrn which is of the datatype Number.(drpPerson is a DropDownList control) 我从中选择的databsase是一个Access数据库,我从三个字段中选择的表是AutoNumber类型的PersonId,Text类型的PersonName和Number类型的StatusIdFrn。(drpPerson是DropDownList控件)

Change this: 更改此:

"SELECT * FROM [Person] WHERE [StatusIdFrn] = '" + statusID + "'"

To this: 对此:

"SELECT * FROM [Person] WHERE [StatusIdFrn] = " + statusID + ""

As [StatusIdFrn] is numeric, you need to discard the single quotes as they indicate a text type. 由于[StatusIdFrn]是数字,因此您需要丢弃单引号,因为它们表示文本类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM