Plz anyone help me ....

I created the database in access with fields type is date/time and text...
But I try to get the value from datetimepicker and combobox..
My struggling code was

cmd=new oledbcommand(insert into sample (doj,designation)values(" & datetimepicker1.value &","&combobox1.text&")",con)

note:- database connection is successfull!...

What's the error that is produced if there is any?

To clarify my previous post, convert the DateTimePicker value using format as in my previous post.

Also, you date should be enclosed in # characters and your text in ' characters, so INSERT INTO SAMPLE (DOJ,DESIGNATION)VALUES(#" & DATETIMEPICKER1.VALUE &"#,'"&COMBOBOX1.TEXT&"')"

Or better yet, use parameterised queries:

cmd=new oledbcommand(INSERT INTO SAMPLE (DOJ,DESIGNATION)VALUES(?, ?)",CON)
cmd.Parameters.AddWithValue("?", YourDatePicker)
cmd.Parameters.AddWithValue("?", YourComboBox)

cmd.ExecuteNonQuery()

to avoid the need to enclose field values in special characters and to avoid potential SQL injection attacks.

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.