0
我加載了一些ADO.net對象:SQLDATETIME集數據行列設置爲空
Dim conPERP As New System.Data.SqlClient.SqlConnection(OISConnectString)
Dim cmd As New System.Data.SqlClient.SqlCommand("", conPERP)
daCERTs.SelectCommand = New SqlCommand("SELECT * FROM PERP_Certs_DMS", conPERP)
Dim cmdBldr As New SqlCommandBuilder(daCERTs)
daCERTs.Fill(dsCERTs)
daCERTs.FillSchema(dsCERTs, System.Data.SchemaType.Mapped) ' later troubleshooting attempt
dtCERTs = dsCERTs.Tables(0)
使用SQL Server 2008中的一個在dtCERTs列是SQL datetime類型。該列可以爲空。報告已經有一個值,但我需要將其設置回NULL。
sWhere = $"registrationNo={c("regNo")} AND Instance_ID={sInst}"
row = dtCERTs.Select(sWhere)(0)
row("Why_Archived") = DBNull.Value ' varchar - works
row("Record_Archive_Date") = SqlDateTime.Null ' causes error
最後行導致錯誤:
Unable to cast object of type 'System.Data.SqlTypes.SqlDateTime'
to type 'System.IConvertible'.Couldn't store <Null>
in Record_Archive_Date Column. Expected type is DateTime.
Null.Value不起作用。
SqldateTime.Null.Value會導致錯誤:「數據爲空,無法在空值上調用此方法或屬性。」
如何將datetime列設置爲NULL?
作品 - 可以發誓我試過了。 – rheitzman