Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query error - "Column cannot be null"

I have a SQL query:

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

like image 424
Ishan Avatar asked Oct 13 '22 21:10

Ishan


1 Answers

From the 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.

Use this:

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(); 
like image 191
Quassnoi Avatar answered Oct 18 '22 03:10

Quassnoi