DateTime Field, Insert a Null value.
- From: "tclancey" <tull@xxxxxxxxxxxxxxxx>
- Date: Tue, 10 Apr 2007 12:16:51 +0100
Hi. I'm having some problems getting a Null value into an SQL DateTime
field. I'm all googled out, but I did find a bit of code using the
parameters that looked as if it might do the job, but unfortunately any
nullDate saved in the column is stored as Now. My SQL column is set to
allow nulls. Can ayone show me where I'm going wrong?
Cheers,
Tull.
If DbType = "MSSQL" Then
sql &= ", @User19, @User20);"
Dim con As New SqlConnection(MsSqlConnString)
Dim com As New SqlCommand(sql, con)
com.Parameters.Add(New SqlParameter("@User19", SqlDbType.DateTime))
com.Parameters.Add(New SqlParameter("@User20", SqlDbType.DateTime))
Dim nullDate As SqlDateTime = SqlDateTime.Null
If dpkUser19.Checked = True Then com.Parameters("@User19").Value =
SqlDate(dpkUser19.Value.ToShortDateString) Else
com.Parameters("@User19").Value = nullDate
If dpkUser20.Checked = True Then com.Parameters("@User20").Value =
SqlDate(dpkUser20.Value.ToShortDateString) Else
com.Parameters("@User20").Value = nullDate
con.Open()
com.ExecuteNonQuery()
com.Dispose()
Dim lid As New SqlCommand("SELECT @@IDENTITY", con)
LastID = CLng(lid.ExecuteScalar)
lid.Dispose()
con.Dispose()
End If
.
- Follow-Ups:
- Re: DateTime Field, Insert a Null value.
- From: tclancey
- Re: DateTime Field, Insert a Null value.
- Prev by Date: Re: User authentication
- Next by Date: Re: DateTime Field, Insert a Null value.
- Previous by thread: Re: User authentication
- Next by thread: Re: DateTime Field, Insert a Null value.
- Index(es):
Loading