INSERT INTO STATEMENT syntax error

L

l1c0r

i have to this string;

strDate = Trim(Format(Now, "MM/dd/yyyy"))

then my insert into statement looks like this;

DBInsert.CommandText = "Insert Into Leads " _
&
"(LeadID,StaffMember,LeadFrom,SName,Address,City,State,ZipCode,Sqft,Bedroom,Bath,Price,Phone1,Phone2,Email,DateC,Contact,MailedAddress,EmailedAddress,Callback,Notes)
" _
& "Values (" _
& "'" & strID & "', " _
& "'" & strMember & "', " _
& "'" & strFrom & "', " _
& "'" & strSellers & "', " _
& "'" & strAdd & "', " _
& "'" & strCty & "', " _
& "'" & strSt & "', " _
& "'" & strZip & "', " _
& "'" & strSqft & "', " _
& "'" & strBed & "', " _
& "'" & strBath & "', " _
& "'" & strPrice & "', " _
& "'" & strPhone1 & "', " _
& "'" & strPhone2 & "', " _
& "'" & strEmail & "', " _
& "'" & strDate & "', " _
& "'" & strContact & "', " _
& "'" & strMailAdd & "', " _
& "'" & strEmailAdd & "', " _
& "'" & strCallBack & "', " _
& "'" & strNotes & "')"

I cant insert that string into DateC which is not a datefield, is just
a text field, i tried everything i could. any help on why is this
returning a INSERT INTO STATEMENT syntax error?
 
P

pvdg42

l1c0r said:
i have to this string;

strDate = Trim(Format(Now, "MM/dd/yyyy"))

then my insert into statement looks like this;

DBInsert.CommandText = "Insert Into Leads " _
&
"(LeadID,StaffMember,LeadFrom,SName,Address,City,State,ZipCode,Sqft,Bedroom,Bath,Price,Phone1,Phone2,Email,DateC,Contact,MailedAddress,EmailedAddress,Callback,Notes)
" _
& "Values (" _
& "'" & strID & "', " _
& "'" & strMember & "', " _
& "'" & strFrom & "', " _
& "'" & strSellers & "', " _
& "'" & strAdd & "', " _
& "'" & strCty & "', " _
& "'" & strSt & "', " _
& "'" & strZip & "', " _
& "'" & strSqft & "', " _
& "'" & strBed & "', " _
& "'" & strBath & "', " _
& "'" & strPrice & "', " _
& "'" & strPhone1 & "', " _
& "'" & strPhone2 & "', " _
& "'" & strEmail & "', " _
& "'" & strDate & "', " _
& "'" & strContact & "', " _
& "'" & strMailAdd & "', " _
& "'" & strEmailAdd & "', " _
& "'" & strCallBack & "', " _
& "'" & strNotes & "')"

I cant insert that string into DateC which is not a datefield, is just
a text field, i tried everything i could. any help on why is this
returning a INSERT INTO STATEMENT syntax error?
What DBMS are you using and please quote the error message you get.
 
M

Miha Markic [MVP C#]

It is probably due to date formatting.
You should really switch to parametrised commands (using parameters instead
of injecting values into sql statement).
 
L

l1c0r

MS Access, "Syntax Error in INSERT INTO" -> the error, and this is
being done in Visual Basic.Net, my first time doing databases btw..
 
P

pvdg42

l1c0r said:
MS Access, "Syntax Error in INSERT INTO" -> the error, and this is
being done in Visual Basic.Net, my first time doing databases btw..
I think you need to do something with Now (a DateTime object) to convert it
to a string. Along these lines from an example subprocedure...

Public Shared Sub DisplayNow(ByVal title As String, ByVal inputDt As
DateTime)
Dim dtString As String = inputDt.ToString(datePatt)
Console.WriteLine("{0} {1}, Kind = {2}", title, dtString,
inputDt.Kind)
End Sub 'DisplayNow
 

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

Top