Results 1 to 3 of 3

Thread: Date Field

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2010
    Posts
    19

    Date Field

    Hi I am new to VB 2010. I have the following code which saves the data from 4 text boxes. The last one is a date field (txtdate) in the database and it gives me error on it. Can you please let me know what is the syntax to specify a date value? I tried with and without quotes. But didn't work.
    Code:
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
            Dim cn As New OleDb.OleDbConnection
            cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Test\db1.mdb;Persist Security Info=True"
            cn.Open()
            Dim Command As OleDb.OleDbCommand
    
            Command = New OleDb.OleDbCommand("INSERT INTO Projects1(ProjectID, ProjectName, ProjectDesc, ProjectDate)" & _
            " VALUES (" & txtid.Text & ",'" & txtname.Text & "', '" & txtdesc.Text & "', '" & txtdate.Text & "')", cn)
            Command.ExecuteNonQuery()
            cn.Close()
            MsgBox("New Records Added to the database")
        End Sub
    Last edited by sn15164; Jan 14th, 2012 at 08:49 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width