There are alot of resources on this site and on google explaining how to create a paramterized query.
Solution 2
use something like:
GridViewItem.Rows[0].Cells[1].ToString[].Replace["'","''"]
or maybe
GridViewItem.Rows[0].Cells[1].ToString[].Replace["'","\'"]
I'm not really sure because of the many sql languages, but you can easily try one of these and see what happens
Comments
I am doing transaction management process. Will this formula work there for three or more transactions?
The following error “Unclosed quotation mark after the character string…” occurs when you miss a quotation mark.
When the single quote is used once, and to close the statement SQL Server is expecting another single quote. For some reason, a user can forget to do it. For example:
BACKUP DATABASE Adventureworks TO DISK = 'diff.bak
In this case, SQL Server will send the following error message:
Msg 105, Level 15, State 1, Line 1 Unclosed quotation mark after the character string 'diff.bak'.
Also, assume that the statement has been copied from an MS Word document or website to SSMS and the “Unclosed quotation mark after the character string…” error appears. This happened because a single quote in MS Word or website [ ‘ ] is different from a single quote in SSMS [ ‘ ].
To fix this error just put another single quote at the beginning or at the end of the statement where it is needed:
I work on sql server 2012 i face syntax error when run query below
SELECT PartID,Code,Co.CodeTypeID,Co.RevisionID,Co.ZPLID,Count[1] as ConCount
FROM
[ExtractReports].dbo.PartAttributes PM
INNER JOIN [ExtractReports].dbo.Condition Co ON Co.ZfeatureKey = PM.ZfeatureKey Where [1=1 and [PM.ZfeatureKey= 1506990046 And Name ='Aluminum'] Or [PM.ZfeatureKey= 1506990006 And Name ='Unthreaded'] Or [PM.ZfeatureKey= 1506990016 And Name Not In['
# 4-40','
# 6-32','
# 1-64','
# 1-72','
# 8-32','
# 10-32','
# 2-56','
# 2-64','
# 3-48','
# 4-36','
# 3-56','
# 4-48','
# 6-40','
# 0-80','
# 5-40','
# 10-24','
# 12-24','
# 2-28','
# 4-20','
# 8','
# 4','
# 6','
# 2','
# 10','
# 14','
# 10-16','
# 2-32','
# 0.25-20','
# 8-18','
# 12-14','
# 4-4','
# 6-13','] ] Group By PartID,Code,Co.CodeTypeID,Co.RevisionID,Co.ZPLID Having Count[1]>= 3
so after un query above i get these syntax error so how to solve this issue and why this error done
Msg 105, Level 15, State 1, Line 4 Unclosed quotation mark after the character string '] ] Group By PartID,Code,Co.CodeTypeID,Co.RevisionID,Co.ZPLID Having Count[1]>= 3 '. Msg 102, Level 15, State 1, Line 4 Incorrect syntax near '] ] Group By PartID,Code,Co.CodeTypeID,Co.RevisionID,Co.ZPLID Having Count[1]>= 3