CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2008
    Posts
    74

    query with "special" character to save

    hi,
    i need perform the following query to save into db the problem is sometimes the user
    enter some characteres that interfer with the sql command for example

    if the user enter this word: 'hello'
    when i try save this result i error because the final query is this:

    insert into x (v) values (''hello'') and for update this problem ocorr to
    how can i save the value ' to the db replacing the ' charater for other?
    thanks a lot for your help

  2. #2
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: query with "special" character to save

    Use parameterized queiries.

    Code:
    DIM ID as integer = 15
    dim MyName as String = "O'Riely"
    SqlCommand.CommandText = "UPDATE TABLE SET MyName=@MN WHERE ID=@ID"
    SqlCommand.Parameters.AddWithValue("@MN",MyName)
    SqlCommand.Parameters.AddWithValue("@ID",ID)
    SqlCommand.ExequteNonQuery

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

Featured