Share via


GetDate() vb.net and SQL

Question

Wednesday, July 14, 2010 8:36 PM

Private Sub btnAddCustomer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddCustomer.Click

    Dim CustomerID As Guid
    Dim CustomerName As String = ""
    Dim dateMade As DateTime
    Dim strSQL As String
    Dim blnCustomerExist As Boolean = False

    Try

      blnCustomerExist = CheckCustomers()
      If Not blnCustomerExist Then
        dateMade = DateTime.Now
        CustomerID = New Guid

        CustomerName = cboSelectCustomer.Text

        strSQL = "INSERT INTO tblCustomers (CustomerID, CustomerName, Enabled, DateMade) "
        strSQL = ("VALUES ('" & CustomerID.ToString & "','" & CustomerName.ToString & "','1','" & dateMade.ToString & "')")
      Else

        MessageBox.Show("Customer already exists...")

      End If


      'Insert User info into tblCustomers

    Catch ex As Exception


    End Try

    'ADDS New customer  txtJobNumber.Text = cboSelectCustomer.SelectedValue.ToString

  End Sub

Where exactly do i put the "getDate()" in my code.  I know it goes in the SQL, but how?

 

Regards,

MIS

All replies (3)

Wednesday, July 14, 2010 8:49 PM âś…Answered | 1 vote

currently you're getting the date in VB and sending it to the database.  If you want the database to determine the time on it's own then just replace

"','1','" & dateMade.ToString & "')")

with

"','1',GETDATE())")


Wednesday, July 14, 2010 8:38 PM

Im thinking that the above solution will insert the curent date in the database. Is this correct?  OR is it wrong.


Monday, October 7, 2013 3:46 PM

hi , i don't know what the checkcustomers() ?

 blnCustomerExist = CheckCustomers()