Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

Integer variables into SQL statement (VB)

Can someone show my mistake plz


oRs.Open "INSERT INTO tbl_Profiel(ProfielNaam,Hoogte,Breedte,Lengte) VALUES ('" & siLaserfile.Value & "','&ndHoogte_nieuw.Value&','&ndBreedte_nieuw.Value&','&ndLengte_nieuw.Value&')", oConn

thx
0
contec_dev
Asked:
contec_dev
1 Solution
 
contec_devAuthor Commented:
hoogte,breedte,lengte are integer values i read from an inputbox
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Dim sSQL as String

sSQL = "INSERT INTO tbl_Profiel(ProfielNaam, Hoogte, Breedte, Lengte)
sSQL = sSQL & "VALUES (" & siLaserfile.Value & ", " & ndHoogte_nieuw.Value & ", " & ndBreedte_nieuw.Value & ", " & ndLengte_nieuw.Value & ")"

oRs.Open sSQL, oConn

Integer values do not require single quote marks ( ' ) surrounding them.  Only strings need them.
0
 
jefftwilleyCommented:
oRs.Open
"INSERT INTO tbl_Profiel(ProfielNaam,Hoogte,Breedte,Lengte)

VALUES (' " & siLaserfile.Value & " ', ' & ndHoogte_nieuw.Value & ', ' &ndBreedte_nieuw.Value & ', ' & ndLengte_nieuw.Value & ' & " ) ", oConn
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
MageDribbleCommented:
There are missing double quotes in your SQL string that you are providing to the recordset.  If you were inserting character types then the string below would work.  

Jimhorn is correct about integers not needing single quotes.  His SQL statement will work for you

oRs.Open "INSERT INTO tbl_Profiel(ProfielNaam,Hoogte,Breedte,Lengte) VALUES ('" & _
siLaserfile.Value & "',' " & ndHoogte_nieuw.Value & "','" & ndBreedte_nieuw.Value & "','" & ndLengte_nieuw.Value & "')", oConn
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
(slight correction)

Dim sSQL as string

sSQL = "INSERT INTO tbl_Profiel(ProfielNaam, Hoogte, Breedte, Lengte) "   '<-- I forgot the right double-quote mark
sSQL = sSQL & "VALUES (" & siLaserfile.Value & ", " & ndHoogte_nieuw.Value & ", " & ndBreedte_nieuw.Value & ", " & ndLengte_nieuw.Value & ")"

oRs.Open sSQL, oConn

0
 
Arthur_WoodCommented:
actually, this code:

oRs.Open "INSERT INTO tbl_Profiel(ProfielNaam,Hoogte,Breedte,Lengte) VALUES ('" & _
siLaserfile.Value & "',' " & ndHoogte_nieuw.Value & "','" & ndBreedte_nieuw.Value & "','" & ndLengte_nieuw.Value & "')", oConn

should be:

oRs.Open "INSERT INTO tbl_Profiel(ProfielNaam,Hoogte,Breedte,Lengte) VALUES ('" & _
siLaserfile.Value & "', " & ndHoogte_nieuw.Value & "," & ndBreedte_nieuw.Value & "," & ndLengte_nieuw.Value & ")", oConn

as jimhorn said, the NUMBER fields (hoogte,breedte,lengte ) do NOT need to be enclosed in '...'

AW
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now