Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6905251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:09:40+00:00 2026-05-27T08:09:40+00:00

I am having an issue with the SQLCommand query update handling apostrophes. I have

  • 0

I am having an issue with the SQLCommand query update handling apostrophes. I have a gridview that accepts edited text which might have apostrophes and other such accent characters.

The UPDATE keeps throwing errors on the apostrophes in the text entered causing the SQL UPDATE to fail.

Here is the code:

Dim lbl1 As Label = GridView3.Rows(e.RowIndex).Cells(0).FindControl("Label1")
IDVal = lbl1.Text

' New translation
Dim TB1 As TextBox = GridView3.Rows(e.RowIndex).Cells(0).FindControl("TextBox1")
updateString = TB1.Text
updateString = HttpUtility.HtmlAttributeEncode(updateString)

' Brief Description
Dim TB2 As TextBox = GridView3.Rows(e.RowIndex).Cells(0).FindControl("TextBox2")
newBrief = TB2.Text

If newBrief = "" Then
    newBrief = DBNull.Value.ToString
Else
   newBrief = TB2.Text
End If

'    update the corresponding string value for Record
rootTableUpdate = "UPDATE " + userTable + " SET lang_String = '" + updateString + "', date_Changed ='" + myDate + "', prev_LangString = '" + Session("oldString") + "', brief_Descrip = '" + newBrief + "', needsTranslation = 'False', submittedBy= '" + userName + "' WHERE [Id] = " + IDVal + ";"

Dim command1 As New SqlCommand(rootTableUpdate, connection)
connection.Open()
command1.ExecuteNonQuery()
connection.Close()

The word that error’d below is actually: d'alimentation.

Incorrect syntax near ‘alimentation’.
Unclosed quotation mark after the character string ‘ WHERE [Id] = 258;’.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:

System.Data.SqlClient.SqlException: Incorrect syntax near ‘alimentation’.
Unclosed quotation mark after the character string ‘ WHERE [Id] = 258;’.

Source Error:

Line 164:            Dim command1 As New SqlCommand(rootTableUpdate, connection)
Line 165:            connection.Open()
Line 166:            command1.ExecuteNonQuery()

SQEE, VB.net

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:09:41+00:00Added an answer on May 27, 2026 at 8:09 am

    Your code is prone to SQL Injection.

    Use Parameterized queries.

    Dim cmd As New SqlCommand("UPDATE Table SET ColA=@ColA, ColB=@ColB", Conn)
    cmd.Parameters.Add("@ColA", SqlDbType.Int).Value = ColA
    cmd.Parameters.Add("@ColB", SqlDbType.Int).Value = ColB
    cmd.ExecuteNonQuery()
    

    This will also prevent the issues you are having with apostrophe’s.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having an issue here that I have tried everything I can think of but
I'm having an issue with a query that currently uses LEFT JOIN weblog_data AS
We have a device that support SAE J1939 interface and having issue with finding
I'm having issue assigning regex value to a string. Issue that I have is
I'm having an issue with a standard ASP.NET page that has a TextBox and
I'm having a memory leak issue in a service program that runs SQL scripts
Experts, I'm having issue when sending emails out. Currently, I have a feedback form
I have a query that should always be returning a single int. I have
I'm having issue with Action Listener of a JTable that being updated according the
I am having issue in checking which input has been clicked using unobstructive javascript.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.