Reputation: 9043
I am trying to populate a Dataset based on a specific Selection ID but get the error
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)
Upvotes: 1
Views: 5526
Reputation: 4993
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.
Upvotes: 5