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