Datareader to insert Null Date
-
I want to be able to insert into the field if the user doesn't enter a date, but the only way I've gotten the code to work so far is by the following, then concatenating an SQL Statement. I'm using SPROCS just yet, but I will in the near future: Dim dEndDate As Date If IsDBNull(RDR("End Date")) Then dEndDate = "01/01/1900" Else dEndDate = RDR("End Date") End If I did try: If IsDBNull(RDR("End Date")) Then dEndDate = ctype(dbnull.value, date) ...but this didn't work.
-
I want to be able to insert into the field if the user doesn't enter a date, but the only way I've gotten the code to work so far is by the following, then concatenating an SQL Statement. I'm using SPROCS just yet, but I will in the near future: Dim dEndDate As Date If IsDBNull(RDR("End Date")) Then dEndDate = "01/01/1900" Else dEndDate = RDR("End Date") End If I did try: If IsDBNull(RDR("End Date")) Then dEndDate = ctype(dbnull.value, date) ...but this didn't work.
Hi I'm not sure that this will be answer your question Working with dates is usually a bit of a headache, even more if you are developing international software products.The only advice I can give you is to keep your dates always as date object, never use dates as string ex. dEndDate = "01/01/1900" dEndDate = New Date(1900, 1, 1) This will insure that you will not have date issues between your UI and DB. You would be able to assign a dbnull to RDR("End Date") ,if RDR("End Date") the column datatype is date, and it also nulls. If you retrieve the datatable directly from the DB the rules implied on the table in the DB will apply on the datacolumn If you create the datacolumn on the fly specief the DataType and AllowDBNull ex. Dim oColumn As New DataColumn("End Date") oColumn.DataType = System.Type.GetType("System.DateTime") oColumn.AllowDBNull = True Hope it helps. Africa is a tough country --"Hello daar vir die Afrikaans sprekende"--