I want a permanent solution to this Problem.

Hello,

Using Microsoft SQL server as my Database
I've been trying to Save a Record containing an Approstophe,Using an INSERT Statement and it is always coming up with an Error Message "Invalid Character Near ...."

e.g
Dim conn as new AdoDB.Connection
conn.open("dsn=MyDatabase") 'Opening Connection
Dim mario as String

mario ="God's Property"
conn.Execute ("INSERT into MyTable (Description)values('"& mario &"')")

The above Code is what I use and how I've been using it. I would Appriciate Any Comments,Suggestions from Any body in House.
Thanks and Bye.

Comments

  • : Hello,
    :
    : Using Microsoft SQL server as my Database
    : I've been trying to Save a Record containing an Approstophe,Using an INSERT Statement and it is always coming up with an Error Message "Invalid Character Near ...."
    :
    : e.g
    : Dim conn as new AdoDB.Connection
    : conn.open("dsn=MyDatabase") 'Opening Connection
    : Dim mario as String
    :
    : mario ="God's Property"
    : conn.Execute ("INSERT into MyTable (Description)values('"& mario &"')")
    :
    : The above Code is what I use and how I've been using it. I would Appriciate Any Comments,Suggestions from Any body in House.
    : Thanks and Bye.
    :
    As you have found the appostrophe breaks SQL codes. You need to write a function that will replace a single appostrophe with a double appostrophe.

    Your can find functions related to this on the Microsoft site.

    Hope this helps

    John ;-)
  • : Hello,
    :
    : Using Microsoft SQL server as my Database
    : I've been trying to Save a Record containing an Approstophe,Using an INSERT Statement and it is always coming up with an Error Message "Invalid Character Near ...."
    :
    : e.g
    : Dim conn as new AdoDB.Connection
    : conn.open("dsn=MyDatabase") 'Opening Connection
    : Dim mario as String
    :
    : mario ="God's Property"
    : conn.Execute ("INSERT into MyTable (Description)values('"& mario &"')")
    :
    : The above Code is what I use and how I've been using it. I would Appriciate Any Comments,Suggestions from Any body in House.
    : Thanks and Bye.

    [code] Dim conn as new AdoDB.Connection
    conn.open("dsn=MyDatabase") 'Opening Connection
    Dim mario as String

    mario ="God's Property"
    [blue]mario=replace(mario, "'", "''")[/blue]
    conn.Execute ("INSERT INTO MyTable (Description) VALUES ('"& mario &"')")
    [/code]
    INSERT INTO MyTable (Descrtiption) VALUES ('God's Property')
    causes error because if u use equivalent VB syntax:
    INSERT INTO MyTable (Descrtiption) VALUES ("God"s Property")
    - threetimes quotation marks on line.. error!
    After replace function will the SQL looks like
    INSERT INTO MyTable (Descrtiption) VALUES ('God''s Property')
    ...
    Because
    SELECT 'God''s Property'
    returns
    God's Property



    [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]

    [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories