473,503 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Incorrect Syntax Near - Unclosed Quotation Mark After The Character String

1 New Member
Expand|Select|Wrap|Line Numbers
  1. protected void btn_Edit_Click(object sender, EventArgs e)
  2.     {
  3.         Panel1.Visible = true;
  4.         Button5.Visible = true;
  5.         if (FileUpload1.HasFile)
  6.         {
  7.             //string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
  8.             //FileUpload1.SaveAs(Server.MapPath(filename));
  9.             string filename = "~/Uploads/" + FileUpload1.FileName;
  10.             FileUpload1.SaveAs(Server.MapPath(filename));
  11.  
  12.             conn.Open();
  13.             if (TextBox10.Text != "")
  14.             {
  15.                 SqlCommand cmd = new SqlCommand("UPDATE Question_tbl SET ExamName='" + ddl_ExamName.Text + "',SubjectName='" + ddl_SubjectName.Text + "',TopicName='" + ddl_TopicName.Text + "',QuestionLevel='" + ddl_QuestionLevel.Text + "',QuestionMmarking='" + tb_QMarking.Text + "',QuestionType='" + ddl_QType.Text + "',Question='" + tb_Question.Text + "',Option1='" + tb_Option1.Text + "',Option2='" + tb_Option2.Text + "',Option3='" + tb_Option3.Text + "',Option4='" + tb_Option4.Text + "',CorrectOption='" + tb_CorrectOption.Text + "',Solution='" + tb_Solution.Text + "',AImage='" + filename + "' where QuestionId='" + TextBox10.Text + "'", conn);
  16.                 cmd.ExecuteNonQuery();
  17.                 Page.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
  18.                 Response.Write("Sucessfully updated..");
  19.  
  20.             }
  21.             ClearText();
  22.             conn.Close();
  23.         }
  24.     }

here is my code and it is giving this error.."Incorrect Syntax Near s - Unclosed Quotation Mark After The Character String"

please help in solving this problem its urjent...
Sep 14 '12 #1
2 4502
Rabbit
12,516 Recognized Expert Moderator MVP
Please use code tags when posting code.

The most likely cause is that one of your variables has a quote in its value. You need to either parameterize your query or escape the quotes. Otherwise you open yourself up to these errors and SQL injection attacks.
Sep 14 '12 #2
donbock
2,426 Recognized Expert Top Contributor
Is this a compile-time error or is perhaps a run-time error generated by SQL?
Sep 14 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
9887
by: Carl | last post by:
Can you tell me what is wrong with this syntax ? string select = "UPDATE .. " + "(,,,,,,, ,,,, ,,, , , , ) " + " VALUES (@id,@clientid,@total,@tps,@tvq,@gtotal,@datefac,@datepay,
11
7084
by: Mark Findlay | last post by:
Hello Experts! I am attempting to use the OleDbCommand.ExecuteScaler() function within my ASP.NET C# web page to perform a simple validation, but receive the following error: "Incorrect...
0
1293
by: Iham Sheen | last post by:
Hi, When I click at the Update button to commit changes in a MxDataGrid, I get the error message "Unclosed quotation mark ...." if there is a single quote in any of the columns. How can I work...
1
2329
by: iporter | last post by:
In the following code, the two Response.Write statements output exactly the same - I can copy and paste both into Query Analyzer, and run them fine. However, if I comment out line 3, the...
0
8291
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new...
5
4481
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Hi, What is wrong with this code ? I got this error: " Line 1: Incorrect syntax near 'sp_Collect'. " which appears at the last line when | call the cm.ExecuteScalar . The sp takes an int ID...
1
6229
by: karenkksh | last post by:
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. ...
43
8493
by: dougancil | last post by:
Can someone please review my code and see where I can be missing information. I get the following error: Line 1: Incorrect syntax near ','. Unclosed quotation mark before the character string '...
1
4445
by: Omendra | last post by:
Hi, I am using SQL Server 2005 and i am using Stored Procedure something like :- I am getting error:- Msg 170, Level 15, State 1, Line 18: Incorrect syntax near 'MAX'. DECLARE @jid AS...
3
7458
by: Aisya | last post by:
Hye, I need help to overcome the problem mention above. My application needs user to key in their details, but when it comes to name some names has an apostrophe, somehow it's okay to save the...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.