Passing a null parameter

  • Thread starter Thread starter Chuck Salvo
  • Start date Start date
C

Chuck Salvo

I'm connected to Sybase ASA version 8.02

Trying to execute the following command:

myCommand.Connection = OleDbConnection1
myCommand.Transaction = myTrans
cmd = "INSERT INTO mvr_viol
(servicekey,source,info,viol,conv,description,code,points,acd,avd,disposition)"
cmd = cmd & " VALUES (?,1,?,?,?,?,?,?,?,?,?)"
myCommand.CommandText = cmd

I create the 10 parameters, fill them with data, and the
ExecuteNonQuery works fine.

However, is some cases I need one of the columns set to "NULL"
so in that case there is this snippet:

myCommand.Parameters(3).IsNullable = True
myCommand.Parameters(3).Value = DBNull.Value

However, this time the ExecuteNonQuery fails with the message:
"Count field incorrect: Not enough values for host variables"

There are still 10 parameters, yet it fails. Can this be made to work?
 
Instead of DBNull.Value try
Imports System.Data.SqlTypes

myCommand.Parameters(3).Value = SQLString.Null
OR
myCommand.Parameters(3).Value = SqlInt32.Null

I hope this helps.
I'm trying to do it without a parameter object.
 
Back
Top