2010-10-28 16 views
5

Mam kwerendy SQL:SQL Błąd zapytania - "Kolumna nie może być null"

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

+3

wydaje się oczywiste dla mnie –

+0

mam już wartość w string.but to nie czuło się zapytania sql – Ishan

+1

ODBC - czy to z wyboru? –

Odpowiedz

4

Z 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.

użyj:

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

i jak zdefiniować wartość dla "?". w jaki sposób zapytanie wie, co to jest? – Ishan

+0

@user: dodaj parametr do kolekcji. Będzie wiedział o kolejności, w jakiej został dodany: pierwszy dodany parametr to pierwszy "?" Itp. Jest to cytat, który skopiowałem. – Quassnoi

+0

Dziękuję SIR !! jego działanie: – Ishan

0

będzie ci pomocna

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

Najlepsza metoda przeciążania pasująca do "System.Data.Odbc.OdbcParameterCollection.Add (string, System.Data.Odbc.OdbcType, int)" zawiera nieprawidłowe argumenty – Ishan

Powiązane problemy