Sql AddWithValue()不是';t接受DBNull.Value(异常0x800A0BB9)-Silverlight-VB

Sql AddWithValue()不是';t接受DBNull.Value(异常0x800A0BB9)-Silverlight-VB,sql,vb.net,silverlight,parameters,ado,Sql,Vb.net,Silverlight,Parameters,Ado,我正在开发一个OOB Silverlight应用程序,并使用COM工具包(),语言是VisualBasic(VB)。使用此软件包,我可以使用ADO.NET将我的应用程序连接到我的Microsoft SQL Server数据库。它可以工作,但当我尝试向参数插入空值时,它会引发异常:0x800A0BB9() 我的代码是(我将发布最简单的扩展): 班级工作: Public Class Job Property Code() As Integer Property Name() As S

我正在开发一个OOB Silverlight应用程序,并使用COM工具包(),语言是VisualBasic(VB)。使用此软件包,我可以使用ADO.NET将我的应用程序连接到我的Microsoft SQL Server数据库。它可以工作,但当我尝试向参数插入空值时,它会引发异常:0x800A0BB9()

我的代码是(我将发布最简单的扩展):

班级工作:

Public Class Job
    Property Code() As Integer
    Property Name() As String
    Property Desc() As String
End Class
来自作业的Desc值可以为空。如果我把
cmd.Parameters.AddWithValue(“Desc_carg”,DBNull.Value)
它仍然不起作用。我能做什么?(当Desc不为空时,命令工作)

Exception.ToString在这里:

System.Runtime.InteropServices.COMException (0x800A0BB9): Exception from HRESULT: 0x800A0BB9 ---> MS.Internal.ComAutomation.ComAutomationObjectException: The arguments are incorrect, are out of acceptable range, or are in conflict.(Source=ADODB.Parameter) (HelpFile=C:\WINDOWS\HELP\ADO270.CHM#1240641) em MS.Internal.ComAutomation.ComAutomationNative.CheckInvokeHResult(UInt32 hr, String memberName, String exceptionSource, String exceptionDescription, String exceptionHelpFile, UInt32 exceptionHelpContext) em MS.Internal.ComAutomation.ComAutomationNative.Invoke(Boolean tryInvoke, String memberName, ComAutomationInvokeType invokeType, ComAutomationInteropValue[] rgParams, IntPtr nativePeer, ComAutomationInteropValue& returnValue) em MS.Internal.ComAutomation.ComAutomationObject.InvokeImpl(Boolean tryInvoke, String name, ComAutomationInvokeType invokeType, Object& returnValue, Object[] args) em MS.Internal.ComAutomation.ComAutomationObject.Invoke(String name, ComAutomationInvokeType invokeType, Object[] args) em System.Runtime.InteropServices.Automation.AutomationMetaObjectProvider.TrySetMember(SetMemberBinder binder, Object value) em System.Runtime.InteropServices.Automation.AutomationMetaObjectProviderBase.<.cctor>b__3(Object obj, SetMemberBinder binder, Object value) em CallSite.Target(Closure , CallSite , Object , Int32 ) em System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) em CallSite.Target(Closure , CallSite , Object , Int32 ) em ComToolkit.Data.AdoParameter.set_Type(DbType value) em ComToolkit.Data.AdoParameter..ctor(Object adoParameter, String name, Object value) em CallSite.Target(Closure , CallSite , Type , Object , String , Object ) em System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3) em CallSite.Target(Closure , CallSite , Type , Object , String , Object ) em ComToolkit.Data.AdoCommand.CreateParameter(String name, Object value) em ComToolkit.Data.AdoParameterCollection.AddWithValue(String name, Object value) em Corporativo.Dao.CargoDao.AddParameters(AdoCommand cmd, Cargo c) em Corporativo.Dao.CargoDao.CriarCargo(Cargo c) em Corporativo.UCCadCargos.Create()    
System.Runtime.InteropServices.COMException(0x800A0BB9):来自HRESULT的异常:0x800A0BB9-->MS.Internal.ComAutomation.ComAutomationObject异常:参数不正确、超出可接受范围或存在冲突。(Source=ADODB.Parameter)(HelpFile=C:\WINDOWS\HELP\ADO270.CHM\1240641)em MS.Internal.ComAutomation.ComAutomationNative.CheckInvokeHResult(UInt32 hr,String memberName,String exceptionSource,String exceptionDescription,String exceptionHelpFile,UInt32 exceptionHelpContext)em MS.Internal.ComAutomation.ComAutomationNative.Invoke(Boolean tryInvoke,String memberName,ComAutomationInvokeType invokeType,ComAutomationInteropValue[]rgParams,IntPtr nativePeer,ComAutomationInteropValue和returnValue)em MS.Internal.ComAutomation.ComAutomationObject.InvokeImpl(Boolean tryInvoke,String name,ComAutomationInvokeType invokeType,Object和returnValue,Object[]args)em MS.Internal.ComAutomation.ComAutomationObject.Invoke(字符串名称,ComAutomationInvokeType invokeType,对象[]args)em System.Runtime.InteropServices.Automation.AutomationMetaObjectProvider.TrySetMember(SetMemberBinder,对象值)em System.Runtime.InteropServices.Automation.AutomationMetaObjectProviderBase.b\u 3(Object obj,SetMemberBinder binder,Object value)em CallSite.Target(Closure,CallSite,Object,Int32)em System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site,T0 arg0,T1 arg1)em CallSite.Target(Closure,CallSite,Object,Int32)em-ComToolkit.Data.adopparameter.set_Type(DbType value)em ComToolkit.Data.AdoParameter..ctor(对象AdoParameter,字符串名称,对象值)em CallSite.Target(闭包,调用站点,类型,对象,字符串,对象)em System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](调用站点,T0 arg0,T1 arg1,T2 arg2,T3 arg3)em CallSite.Target(Closure,CallSite,Type,Object,String,Object)em-ComToolkit.Data.adocomCommand.CreateParameter(String-name,Object-value)em-ComToolkit.Data.adocParameterCollection.AddWithValue(String-name,Object-value)em-Corporativo.Dao.Cargo.AddParameters(AdoCommand-cmd,Cargo-c)em-Corporativo.Dao.CargoDao.criargo(Cargo-c)em Corporativo.UCCadCargos.Create()
信息:

来自HRESULT的异常:0x800A0BB9


如果值为空,则不应使用
AddWithValue
AddWithValue
根据值推断参数的数据类型,但如果值为空,则无法推断类型。在这种情况下,应使用
Add
,明确指定数据类型并设置
值erty.

请复制/粘贴您的异常,而不是发布链接,这样,如果链接不再工作,这个问题将来可能会帮助其他人。
Nome\u carg
Desc\u carg
是否都接受空值?不,只有Desc\u carg,但我对每个都使用它,因为我对20多个参数有相同的Sub,并且有几个可重设为null。如果我使用
cmd.Parameters.AddWithValue(“Desc_carg”,DBNull.Value)
它也不起作用。
System.Runtime.InteropServices.COMException (0x800A0BB9): Exception from HRESULT: 0x800A0BB9 ---> MS.Internal.ComAutomation.ComAutomationObjectException: The arguments are incorrect, are out of acceptable range, or are in conflict.(Source=ADODB.Parameter) (HelpFile=C:\WINDOWS\HELP\ADO270.CHM#1240641) em MS.Internal.ComAutomation.ComAutomationNative.CheckInvokeHResult(UInt32 hr, String memberName, String exceptionSource, String exceptionDescription, String exceptionHelpFile, UInt32 exceptionHelpContext) em MS.Internal.ComAutomation.ComAutomationNative.Invoke(Boolean tryInvoke, String memberName, ComAutomationInvokeType invokeType, ComAutomationInteropValue[] rgParams, IntPtr nativePeer, ComAutomationInteropValue& returnValue) em MS.Internal.ComAutomation.ComAutomationObject.InvokeImpl(Boolean tryInvoke, String name, ComAutomationInvokeType invokeType, Object& returnValue, Object[] args) em MS.Internal.ComAutomation.ComAutomationObject.Invoke(String name, ComAutomationInvokeType invokeType, Object[] args) em System.Runtime.InteropServices.Automation.AutomationMetaObjectProvider.TrySetMember(SetMemberBinder binder, Object value) em System.Runtime.InteropServices.Automation.AutomationMetaObjectProviderBase.<.cctor>b__3(Object obj, SetMemberBinder binder, Object value) em CallSite.Target(Closure , CallSite , Object , Int32 ) em System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) em CallSite.Target(Closure , CallSite , Object , Int32 ) em ComToolkit.Data.AdoParameter.set_Type(DbType value) em ComToolkit.Data.AdoParameter..ctor(Object adoParameter, String name, Object value) em CallSite.Target(Closure , CallSite , Type , Object , String , Object ) em System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3) em CallSite.Target(Closure , CallSite , Type , Object , String , Object ) em ComToolkit.Data.AdoCommand.CreateParameter(String name, Object value) em ComToolkit.Data.AdoParameterCollection.AddWithValue(String name, Object value) em Corporativo.Dao.CargoDao.AddParameters(AdoCommand cmd, Cargo c) em Corporativo.Dao.CargoDao.CriarCargo(Cargo c) em Corporativo.UCCadCargos.Create()