INSERT INTO STATEMENT syntax error

  • Thread starter Thread starter l1c0r
  • Start date Start date
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?
 
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.
 
It is probably due to date formatting.
You should really switch to parametrised commands (using parameters instead
of injecting values into sql statement).
 
MS Access, "Syntax Error in INSERT INTO" -> the error, and this is
being done in Visual Basic.Net, my first time doing databases btw..
 
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
 
Back
Top