5

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

2
  • i already have value in the string.but it is not geting into sql query Commented Oct 28, 2010 at 10:38
  • Is the column name truly nmae or is it actually name ? Commented Oct 28, 2010 at 10:46

2 Answers 2

4

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(); 
Sign up to request clarification or add additional context in comments.

2 Comments

and how to define value for '?'. how will query know what is ?
@user: add a parameter to the collection. It will know from the order it was added: the first parameter added is the first ?, etc. It's in the quote I copied.
0

it will be helpful to you

cmd.Parameters.Add("@S", OdbcType.Char, S);

1 Comment

The best overloaded method match for 'System.Data.Odbc.OdbcParameterCollection.Add(string, System.Data.Odbc.OdbcType, int)' has some invalid arguments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.