Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Friends,

I am making project for my MCA. It contains a page same like


this page contains a query text box where a user can insert his query. If am inserting a small data then it is inserted correctly. if i am inserting large amount of data in the text box then it is giving an error.

Incorrect syntax near 's'.
An expression of non-boolean type specified in a context where a condition is expected, near 'clicks'.
Unclosed quotation mark after the character string ')'.

default.aspx.cs code is:-
 string str = (@"server=KANHA-PC;database=codeproject; integrated security=true;");
        protected void submit_btn_Click(object sender, EventArgs e)

        private void submit_btn_mtd()
            SqlConnection con = new SqlConnection(str);
            string ques = (query_txtbx.Text).ToString();
            SqlCommand cmd = new SqlCommand("insert into question_tbl(Asker, Sub, Lang, Question) values('" + Session["user"].ToString() + "','" + sub_txtbx.Text + "','" + tagddl.SelectedValue + "','" + ques + "')", con);

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="askquestion.aspx.cs" Inherits="Codeproject.askquestion" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <style type="text/css">
            text-align: justify;
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
      <a href="allquestions.aspx">View all question</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="askquestion.aspx">ask a question</a>&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="Myquest.aspx">Mine</a></p>
        <asp:TextBox ID="sub_txtbx" runat="server" Width="746px"></asp:TextBox>
        <asp:DropDownList ID="tagddl" runat="server">
            <asp:ListItem>Mobile Aplication</asp:ListItem>
        <asp:TextBox ID="query_txtbx" runat="server" Height="384px" Width="748px"
        <asp:Button ID="submit_btn" runat="server" Text="Submit My Question"
            onclick="submit_btn_Click" />
            <input type="Reset" name="Reset" />
    <p class="clear">
        <asp:TextBox ID="TextBox6" runat="server" Height="307px" TextMode="MultiLine"
            Width="686px" AutoCompleteType="Disabled" ReadOnly="True">A few simple rules when posting your question.A few simple rules when posting your question.

   1. Have you searched or Googled for a solution?
   2. Be specific! Don't ask "I need to write a booking application". Specify exactly what it is you need help with.
   3. Keep the subject brief but descriptive. eg "How do I change the dialog colour?"
   4. Keep the question as concise as possible. If you have to include code, include the smallest snippet of code you can - do not dump your entire codebase.
   5. Tag your question appropriately.
   6. Your question may be edited or retagged by others. Anything inappropriate will be removed.
   7. If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
   8. Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
   9. Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read.
  10. Do not be abusive, offensive, inappropriate,harass anyone on the boards or post ads or spam. Doing so will get you kicked off and banned. Play nice</asp:TextBox>

Database table design is:

create table question_tbl
asker nvarchar(100),
Sub nvarchar(1000),
lang varchar(100),
question nvarchar(MAX) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
Q_id int primary key identity(1000,1)
Updated 23-Aug-12 8:40am
Santhosh Kumar Jayaraman 23-Aug-12 6:37am    
post your code
ridoy 23-Aug-12 6:41am    
show code here..

make sure that the column in the database where you are inserting the query has size sa "MAX"
CREATE TABLE [dbo].[tbl_Query](
    [Id] [bigint] NULL,
    [Query] [nvarchar](MAX) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
Share this answer
kanha.460 23-Aug-12 6:52am    
I have defined my query as

query nvarchar(MAX) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

Again it is giving that same error.

Incorrect syntax near 's'.

only this single line of error.
ujju.1 23-Aug-12 6:57am    
can you post the code here which you are writing at the click event of save/submit_button
kanha.460 23-Aug-12 7:11am    
I have posted my code also you can see that
just do this,
txtQuerybox.text = txtQuerybox.text.Replace("''","'");

now, pass 'txtQuerybox.text' as parameter in your sql Query for save/update data.

why this happens?
you have text in textbox like this
student's table ...

that case how insert statement look like
Insert into tbl(fld1) values('student's table ...')

there are 3 single quotes, see underlined portion.
Sql can't deside where the value ends, because starting & ending value is mentioned by single quote & here there are 3 single quotes
Happy Coding!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900