简体   繁体   English

oledb异常未在标准表达式中的c#数据类型不匹配中处理

[英]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(); 在这一部分上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 : 看起来很奇怪,将参数名称从@newProjID.Text@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: 但是,如果newProjID.Text是字符串,则应首先将其解析为int

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

暂无
暂无

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

相关问题 条件表达式中的数据类型不匹配| Access,OleDb,C# - Data type mismatch in criteria expression | Access, OleDb, C# C#访问OleDb条件表达式中的数据类型不匹配 - C# Access OleDb Data type mismatch in criteria expression 类型'System.Data.OleDb.OleDbException'的未处理异常附加信息:条件表达式中的数据类型不匹配 - An unhandled exception of type 'System.Data.OleDb.OleDbException' Additional information: Data type mismatch in criteria expression System.Data.OleDb.OleDbException:“标准表达式中的数据类型不匹配。” C# 错误 - System.Data.OleDb.OleDbException: 'Data type mismatch in criteria expression.' C# error System.Data.OleDb.OleDbException:'条件表达式中的数据类型不匹配。 在C#中 - System.Data.OleDb.OleDbException: 'Data type mismatch in criteria expression. in c# 使用 Oledb、C#、Dapper 的条件表达式中的数据不匹配 - data mismatch in criteria expression using Oledb, C#, Dapper 带有OLEDB的C#中的Excel前缀字符导致UPDATE上的“条件表达式中的数据类型不匹配”错误 - Excel Prefixcharacter in C# with OLEDB causing “Data type mismatch in criteria expression” error on UPDATE C# 标准表达式中的数据类型不匹配 - C# data type mismatch in criteria expression C#中的“条件表达式中的数据类型不匹配” - “Data type mismatch in criteria expression” in C# 条件表达式中的数据类型不匹配 C# - Data type mismatch in criteria expression c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM