Click here to Skip to main content
15,891,204 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:-
C#
 string str = (@"server=KANHA-PC;database=codeproject; integrated security=true;");
        protected void submit_btn_Click(object sender, EventArgs e)
        {
            submit_btn_mtd();
        }

        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);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
}


default.aspx
XML
<%@ 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">
        .style7
        {
            text-align: justify;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <p>
      <a href="allquestions.aspx">View all question</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&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>
    <p>
        Subject
        <asp:TextBox ID="sub_txtbx" runat="server" Width="746px"></asp:TextBox>
    </p>
    <p>
        Tags&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:DropDownList ID="tagddl" runat="server">
            <asp:ListItem>C#</asp:ListItem>
            <asp:ListItem>ASP.NET</asp:ListItem>
            <asp:ListItem>VB.NET</asp:ListItem>
            <asp:ListItem>Mobile Aplication</asp:ListItem>
            <asp:ListItem>Database</asp:ListItem>
            <asp:ListItem>C++</asp:ListItem>
        </asp:DropDownList>
    </p>
    <p>
        <asp:TextBox ID="query_txtbx" runat="server" Height="384px" Width="748px"
            TextMode="MultiLine"></asp:TextBox>
    </p>
    <p>
        <asp:Button ID="submit_btn" runat="server" Text="Submit My Question"
            onclick="submit_btn_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="Reset" name="Reset" />
    </p>
    <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>
    </p>
    <p>
        &nbsp;</p>
</asp:Content>



Database table design is:

SQL
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)
)
Posted
Updated 23-Aug-12 8:40am
v4
Comments
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"
i.e.
SQL
CREATE TABLE [dbo].[tbl_Query](
    [Id] [bigint] NULL,
    [Query] [nvarchar](MAX) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
) ON [PRIMARY]
 
Share this answer
 
Comments
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,
C#
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
 
v2

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