gpt4 book ai didi

c# - SQL 查询错误 - "Column cannot be null"

转载 作者:可可西里 更新时间:2023-11-01 07:06:42 25 4
gpt4 key购买 nike

我有一个 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();

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

最佳答案

来自manual :

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 = ?

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();

关于c# - SQL 查询错误 - "Column cannot be null",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4042002/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com