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

why do you have a datetimepicker and a textbox? you can just use the value or text property of the datetimepicker.

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

i already use the .value property of the datetimepicker and yet nothing save in my table...

hi,
Use datetimepicker.value.date to save the date.
Hope this helps.

@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.

Hi,
try without using"#" it is used for select try this

cmd.CommandText = "INSERT INTO hold ([hdate], des) VALUES (" & DateTimePicker1.Value.Date & ", '" & TextBox1.Text & "')"

Hope it helps as I used it in my code it works well

@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

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..

if this thread already solved.
please mark as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.