[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

Using OdbcParameter, Error "Column XX cannot be Null"

sleepyant

6/5/2005 2:50:00 PM

Hi, I'm using VB. NET 2003 and MySql. When I try to run the ExecuteNonQuery
part, it keeps giving me this error.

My Code (simplified):

Dim cmdSql As OdbcCommand
Dim Param As OdbcParameter

cmdSql = New OdbcCommand
cmdSql = conn1.CreateCommand

cmdSql.CommandText = "INSERT INTO customer" & _
" SET ic_no = @ic_no"

Param = New OdbcParameter("@ic_no", "123")
cmdSql.Parameters.Add(Param)

Param.SourceVersion = DataRowVersion.Original

cmdSql.ExecuteNonQuery()

---> Error: "Column IC_NO cannot be Null"

What's wrong? I tried before without using the parameter by directly setting
the value in the command, and with no problem. Please help me.


1 Answer

Paul Clement

6/6/2005 2:44:00 PM

0

On Sun, 5 Jun 2005 22:49:49 +0800, "Robert G" <no@nono.no> wrote:

&#164; Hi, I''m using VB. NET 2003 and MySql. When I try to run the ExecuteNonQuery
&#164; part, it keeps giving me this error.
&#164;
&#164; My Code (simplified):
&#164;
&#164; Dim cmdSql As OdbcCommand
&#164; Dim Param As OdbcParameter
&#164;
&#164; cmdSql = New OdbcCommand
&#164; cmdSql = conn1.CreateCommand
&#164;
&#164; cmdSql.CommandText = "INSERT INTO customer" & _
&#164; " SET ic_no = @ic_no"
&#164;
&#164; Param = New OdbcParameter("@ic_no", "123")
&#164; cmdSql.Parameters.Add(Param)
&#164;
&#164; Param.SourceVersion = DataRowVersion.Original
&#164;
&#164; cmdSql.ExecuteNonQuery()
&#164;
&#164; ---> Error: "Column IC_NO cannot be Null"
&#164;
&#164; What''s wrong? I tried before without using the parameter by directly setting
&#164; the value in the command, and with no problem. Please help me.
&#164;

Try using a question mark instead of the parameter name in your CommandText:

cmdSql.CommandText = "INSERT INTO customer" & _
" SET ic_no = ?"

You may also need to specify the Size of the parameter value since it is a string.


Paul
~~~~
Microsoft MVP (Visual Basic)