SQL查询错误-“列不能为空" [英] SQL query error - "Column cannot be null"

查看:149
本文介绍了SQL查询错误-“列不能为空"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQL查询:

String S = Editor1.Content.ToString(); 
     Response.Write(S);    
    string sql = "insert into testcase.ishan(nmae,orders) VALUES ('9',@S)"; 
   OdbcCommand cmd = new OdbcCommand(sql, myConn); 
            cmd.Parameters.AddWithValue("@S", S);  
            cmd.ExecuteNonQuery(); 

错误:System.Data.Odbc.OdbcConnection.HandleError的列订单"不能为空

Error: Column 'orders' cannot be null at System.Data.Odbc.OdbcConnection.HandleError

推荐答案

来自

当CommandType设置为Text时,用于ODBC的.NET Framework数据提供程序不支持将命名参数传递给SQL语句或OdbcCommand调用的存储过程.在这两种情况下,均使用问号(?)占位符.例如:

When CommandType is set to Text, the .NET Framework Data Provider for ODBC does not support passing named parameters to an SQL statement or to a stored procedure called by an OdbcCommand. In either of these cases, use the question mark (?) placeholder. For example:

SELECT * FROM Customers WHERE CustomerID = ?

将OdbcParameter对象添加到OdbcParameterCollection的顺序必须直接对应于命令文本中参数的问号占位符的位置.

The order in which OdbcParameter objects are added to the OdbcParameterCollection must directly correspond to the position of the question mark placeholder for the parameter in the command text.

使用此:

string sql = "insert into testcase.ishan(nmae,orders) VALUES ('9', ?)";
OdbcCommand cmd = new OdbcCommand(sql, myConn); 
cmd.Parameters.AddWithValue("you_can_write_anything_here_its_ignored_anyway", S);  
cmd.ExecuteNonQuery(); 

这篇关于SQL查询错误-“列不能为空"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆