Insert Date into Table

Joined
Nov 22, 2002
Messages
18
Location
Singapore
Hi, I want to insert the date into my table , but error appears when i tried to run.

Here is the code:

Code:
Private Sub CmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSave.Click

        mycommand.Dispose()
            mycommand.Connection = cn
        mycommand.CommandText = "INSERT INTO ReminderTable(Subject,Date,Message) VALUES(@Subject,@Date,@Message) "
            mycommand.Parameters.Add("@Subject", TextBox1.Text)
        mycommand.Parameters.Add("@Date", CDate(TextBox4.Text))
            mycommand.Parameters.Add("@Message", TextBox3.Text)
            Try
                cn.Open()
                If cn.State = ConnectionState.Open Then
                    MessageBox.Show("Connection Opened Successfully")
                    mycommand.ExecuteNonQuery()
                End If
            Catch frans As System.Exception
            MessageBox.Show(frans.ToString)
                Me.Dispose()
            End Try


            cn.Close()

    End Sub
Is there anything wrong with the code?
It went wrong when i try to add the date (textbox4.text), but if i dont use the date and just insert the subject and message, it can run successfully.
The problem is on the date which i dont know why.
when i try to catch the error message, the message is:
SYNTAX ERROR IN INSERT INTO STATEMENT

Please help me...

Thanks in advance
 
In a sql statement the date must have this format: "mm/dd/yyyy". I guess you have to format the date before using it in the sql statement.
 
hi, ive been trying all day to try and try,but it still didnt work.

Can you help me post a very very simple way to insert date format into the access table or the date format to convert the date from the textbox ?

thank you very much for your help
 
after a long day looking for the correct way, suddenly IT WORKS....

I changed the textbox with DateTimePicker
and the value with DateTimePicker1.Value

I have tried this before, but didnt work, but now it works.... :)
but still Im curious why it didnt work for the textbox.

any comments will be much appreciated and thank you for your help :)
 
Back
Top