Results 1 to 3 of 3

Thread: SQL VB problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Location
    Houston
    Posts
    3

    Exclamation SQL VB problem

    I have a query that is returning a value
    Cable Fem 6'
    I am now trying to insert into a new table but keep getting an error statement can not be prepared

    Insert into I2DE100M (I2IZPN, I2PMFAM) VALUES('DSUB FEM LAB 6'', 'DEBO')
    the extra single quote after the 6 is the issue but is needed

    I can go to sql anlizer and put double quotes and it works but how do I get the vb statement to pass the dbl qutes in the query string??

  2. #2
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    You would use the same code as you used in Query Analyzer (with two single quotes where there is one in the data) in your VB program:
    e.g.:
    strSQL = "Insert into I2DE100M (I2IZPN, I2PMFAM) VALUES('DSUB FEM LAB 6'', 'DEBO') "

    if you are using variables for your data (for example from a textbox) and don't know whether or not the incoming data has a single quote, you can use the replace function like so:
    strValue1 = Replace(Text1.Text, "'", "''")
    strValue2 = Replace(Text2.Text, "'", "''")
    strSQL = "Insert into I2DE100M (I2IZPN, I2PMFAM) VALUES('" & strValue1 & '", '" & strValue2 & "') "
    "It's cold gin time again ..."

    Check out my website here.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Location
    Houston
    Posts
    3

    Talking thank you

    thank you very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width