简体   繁体   中英

oledb exception was unhandled in c# Data type mismatch in criteria expression

foreach (object selectedItem in lstProjectMemberID.SelectedItems)
{
    DataRowView dr = (DataRowView)selectedItem;
    String result = dr["user_id"].ToString();
    int intResult = int.Parse(result);

    cmd.CommandText = "INSERT INTO project_users(project_id,user_id) VALUES (@newProjID.Text,@userID)";
    cmd.Parameters.Add(newProjID.Text, OleDbType.Integer).Value = newProjID.Text;
    cmd.Parameters.AddWithValue("@userID", intResult);

    cmd.ExecuteNonQuery();

 }

i have this code and im getting the error Data type mismatch in criteria expression. on this part cmd.ExecuteNonQuery(); :( what will i do?

i think i am wrong with my insert query command because of the intresult

That looks strange, change the parameter name from @newProjID.Text to @newProjID :

cmd.CommandText = "INSERT INTO project_users(project_id,user_id) VALUES (@newProjID,@userID)";
cmd.Parameters.Add("@newProjID", OleDbType.Integer).Value = newProjID.Text;

But if newProjID.Text is a string you should parse it to an int first:

cmd.Parameters.Add("@newProjID", OleDbType.Integer).Value = int.Parse(newProjID.Text);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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