Question Date Saving as 01/01/1900

southdowns

New member
Joined
Dec 16, 2010
Messages
1
Programming Experience
10+
Hi, I have a problem where all my dates are saving as 01/01/1900 when using Today.Date

The code I am using is

VB.NET:
If k = 0 Then
            'open connect to database
            connect()
            'clear the dataset to avoid data collisions
            ds.Clear()
            'clear the select command
            sc = ""
            'building the select command using the textboxes
            sc = "INSERT INTO tblJob (JobNum, OrderNum, CustomerID, LabourCost, MaterialCost, VAT, JobTotal, DateEntered) VALUES ("
            sc += "'" & frmJobDetails.txtJobNo.Text & "', "
            sc += "'" & frmJobDetails.txtOrderNo.Text & "', "
            sc += "'" & frmJobDetails.cmbCustomerName.Text & "', "
            sc += "'" & frmJobDetails.txtLabour.Text & "', "
            sc += "'" & frmJobDetails.txtMaterials.Text & "', "
            sc += "'" & frmJobDetails.txtVAT.Text & "', "
            sc += TotalCost.ToString("C") & ", "
            sc += Today.Date & ")"
            'creates a new data adapter using the select command and dbconn, which inserts new row into tblJob
            da = New SqlDataAdapter(sc, dbconn)
            da.Fill(ds, "tblJob")
        Else : MsgBox("A job with this Job Number already exists.")
        End If
        SQLdr.Close()
        dbconn.Close()

The computer time is correct, and when tracking the variable using stops and the watch tool, all the way through to saving, the date is displayed correctly. However, after saving the date is the default value, 01/01/1900

Any help would be appreciated
 
Last edited:
Use parameters instead - see the link in my signature. It should solve all your problems :)

Alternatively, if you are always sending today's date for DateEntered, use the standard SQL GETDATE() function as the value.
 
I cannot recommend strongly enough that you follow InertiaM's advice. We all use string concatenation to build SQL code to begin with but doing so is just plain bad so the moment you become aware of parameters you should start using them. Dates are a classic case of why parameters are superior. I haven't checked out the link provided but I have also blogged on this topic, so you may like to follow the Blog link in my signature for another perspective.
 
Back
Top