![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |