error in insert date using datetimepicker
good,
i am having trouble on how to insert record date in my access db. i am using hdate as my field and his data type is short date
here is my code
cmd.CommandText = "INSERT INTO hold ([hdate], des) VALUES (#" & myDate & "#, '" & TextBox1.Text & "')"
cmd.CommandText = "INSERT INTO hold ([hdate], des) VALUES (#" & datetimepicker1.text & "#, '" & TextBox1.Text & "')"
cmd.CommandText = "INSERT INTO hold ([hdate], des) VALUES (#" & DateTimePicker1.Value.Date.ToShortDateString & "#, '" & TextBox1.Text & "')"
but none of them insert on the table. the record will view on the datagrid but not on the physical table.
can someone show me the right codes here...
thanks
cyberdaemon
Junior Poster in Training
56 posts since Nov 2010
Reputation Points: 10
Solved Threads: 1
why do you have a datetimepicker and a textbox? you can just use the value or text property of the datetimepicker.
Netcode
Veteran Poster
1,021 posts since Jun 2009
Reputation Points: 43
Solved Threads: 67
actually i just want to save the date e.g holiday of the year for the datetimepicker while the textbox will place the description of that holiday.
can u help me regarding the formatting string of the datetime
cyberdaemon
Junior Poster in Training
56 posts since Nov 2010
Reputation Points: 10
Solved Threads: 1
i already use the .value property of the datetimepicker and yet nothing save in my table...
cyberdaemon
Junior Poster in Training
56 posts since Nov 2010
Reputation Points: 10
Solved Threads: 1
@VN412
still no luck
by the way here's my code
Try
con.Open()
cmd.Connection = con
cmd.CommandText = "INSERT INTO hold ([hdate], des) VALUES (#" & DateTimePicker1.Value.Date & "#, '" & TextBox1.Text & "')"
'included on the insert statement after the dd/mm/yy hh:mm:ss
cmd.ExecuteNonQuery()
MessageBox.Show("One record has been added ")
Catch ex As Exception
MessageBox.Show("sdfsd")
Finally
con.Close()
End Try
some of the code above already used just to save record to my table but still dont have luck.
cyberdaemon
Junior Poster in Training
56 posts since Nov 2010
Reputation Points: 10
Solved Threads: 1
@vn412
i already tried it but still no luck. the record will be view in the datagridview but the year is way back 1900, and the record does not save on the table.
i used access 2007, hol is my field and date/Time his datatype and the format is short date
i only need to save it on the database and later on i'll retrieve it, if the date is declared holiday.. thanks
cyberdaemon
Junior Poster in Training
56 posts since Nov 2010
Reputation Points: 10
Solved Threads: 1
i think i found the error. is it a drier error? coz iam using access 2003 but when i review this codes using 2007 it works..
by the way the thanks for the reply..
cyberdaemon
Junior Poster in Training
56 posts since Nov 2010
Reputation Points: 10
Solved Threads: 1
if this thread already solved.
please mark as solved.
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444