silverstormboy Posted March 18, 2003 Posted March 18, 2003 Hi, I want to insert the date into my table , but error appears when i tried to run. Here is the 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 Quote
Cassio Posted March 18, 2003 Posted March 18, 2003 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. Quote Stream of Consciousness (My blog)
owinterton Posted March 18, 2003 Posted March 18, 2003 If I were you I would try to format the date from the textboxes into variables. It might be easier when you put it into the SQL statement. Quote
silverstormboy Posted March 19, 2003 Author Posted March 19, 2003 hi, i've 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 Quote
silverstormboy Posted March 19, 2003 Author Posted March 19, 2003 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 I'm curious why it didnt work for the textbox. any comments will be much appreciated and thank you for your help :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.