我正在開發一個OOB Silverlight應用程序並使用COM工具包(http://silverlightcom.codeplex.com),該語言是Visual Basic(VB)。使用這個包,我可以使用ADO.NET將我的應用程序與我的Microsoft SQL Server數據庫連接起來。它的工作原理,但是當我嘗試向參數中插入一個空值時,它會拋出一個異常:0x800A0BB9(http://prntscr.com/43zwyr)。AddWithValue()不接受DBNull.Value(異常0x800A0BB9) - Silverlight - VB
我的代碼是(我將發佈最簡單的拉伸):
Private Const SqlCreateJob As String = "insert into Cargos(Nome_carg, Desc_carg) values(?, ?)"
Public Shared Sub CreateJob(ByVal j As Job)
Dim conn As AdoConnection = DbUtil.GetConn
Dim cmd As AdoCommand = conn.CreateCommand
cmd.CommandText = SqlCreateJob
cmd.Parameters.AddWithValue("Nome_carg", j.Name)
cmd.Parameters.AddWithValue("Desc_carg", j.Desc)
For Each p As AdoParameter In cmd.Parameters
If p.Value = Nothing Then
p.Value = DBNull.Value
End If
Next
cmd.ExecuteNonQuery()
conn.Close()
End Sub
和類職位:
Public Class Job
Property Code() As Integer
Property Name() As String
Property Desc() As String
End Class
值說明,從工作,可以爲空。如果我把 cmd.Parameters.AddWithValue("Desc_carg", DBNull.Value)
它仍然不起作用。我能做什麼? (當說明是不是空的命令作品)
的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()
而且.Message:
從HRESULT異常:0x800A0BB9
請複製/粘貼您的異常,而不是發佈鏈接,這樣如果鏈接不再有效,將來可能會幫助其他人。 –
好的,沒問題。 –
'Nome_carg'和'Desc_carg'是否都接受空值? –