我在表中有一个日期字段(smalldatetime),在特定情况下,我需要将日期字段设置为空。目前,将 sqlparameter.value 属性设置为日期时
endDateParam.Value = "5/15/2011"
该字段已更新为正确的日期。但是,将其设置为
endDateParam.Value = System.DbNull.Value
不更新字段。
后面的代码:
Protected Sub ...
For Each r As GridViewRow In gvEmployees.Rows
SqlDataSource1.UpdateCommand = "<stored proc>"
SqlDataSource1.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure
setParameters(r)
gvEmployees.UpdateRow(r.RowIndex, False)
Next
End Sub
Private updateParameters As New List(Of SqlParameter)()
Protected Sub setParameters(ByVal r As GridViewRow)
updateParameters.Clear()
Dim endDate As TextBox = TryCast(r.FindControl("txtEndDate"), TextBox)
Dim endDateParam As New SqlParameter("@enddate", SqlDbType.SmallDateTime)
endDateParam.Direction = ParameterDirection.Input
endDateParam.Value = System.DBNull.Value
updateParameters.Add(endDateParam)
End Sub
Protected Sub Sqldatasource1_Updating(ByVal source As Object, ByVal e As SqlDataSourceCommandEventArgs)
e.Command.Parameters.Clear()
For Each p As SqlParameter In updateParameters
e.Command.Parameters.Add(p)
Next
End Sub
更新
endDateParam.Value = System.Data.SqlTypes.SqlDateTime.Null
似乎仍然没有更新该字段。不返回任何错误。