DateTime (DateTimePicker) SQLCE insert

G

Guest

I have a DateTimePicker called customer_picke
I use it and then want to insert it to a table OrderHdr.DUEDATE which is data type DateTime on my SQLCE D
The code i use to insert is as follows and i receive a datepart error on the insert: I insert the customer_picker as string, maybe that is why but i dont quite understand why the datepart error. Any help muchly appreciate

MessageBox.Show("insert"
MessageBox.Show(customer_picker.Text

Dim strSQL As String = "INSERT into OrderHdr ( " &
" REFRENCE, CUSTNMBR, DOCDATE, DUEDATE, " &
" SLPRSNID, TOTALQTY, " &
" PONUMBER, DELREP, DIVISION, COMMENT, CONTACT ) VALUES ( '" + txtHdrRefrence.Text + "', '" + txtCustNmbr.Text + "', " &
" getdate(), '" + customer_picker.Text + "', '" + SLPRSNID.Text + "', " &
" 0.00, '" + txtPO.Text + "', '" + DelRep + "', '" + cmbOHDiv.Text + "', '" + txtComment.Text + "', '" + tbContact.Text + "')
 
J

Jon Skeet [C# MVP]

marcmc said:
I have a DateTimePicker called customer_picker
I use it and then want to insert it to a table OrderHdr.DUEDATE which
is data type DateTime on my SQLCE DB
The code i use to insert is as follows and i receive a datepart error
on the insert: I insert the customer_picker as string, maybe that is
why but i dont quite understand why the datepart error. Any help
muchly appreciated

The thing to do is drop putting the value straight in the SQL, and
instead use parameters.

See http://www.pobox.com/~skeet/csharp/faq/#db.parameters
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top