0

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

Edited by Reverend Jim: Please do not post in ALL CAPS

4
Contributors
4
Replies
20
Views
2 Years
Discussion Span
Last Post by djjeavons
0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.