有关数据库的问题 [英] question regarding database

查看:63
本文介绍了有关数据库的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我正在为我的MCA进行项目.它包含与
类似的页面

[ ^ ]

该页面包含一个查询文本框,用户可以在其中插入他的查询.如果要插入小数据,则可以正确插入.如果我在文本框中插入大量数据,则显示错误.

"s"附近的语法不正确.
在需要条件"的上下文中在点击"附近指定的非布尔类型的表达式.
字符串)"后的引号引起来.


default.aspx.cs代码为:-

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)
        {
            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



default.aspx

<%@ 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:

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)
)

推荐答案

请确保要在数据库中插入查询的列的大小为sa"MAX"

make sure that the column in the database where you are inserting the query has size sa "MAX"
i.e.
CREATE TABLE [dbo].[tbl_Query](
    [Id] [bigint] NULL,
    [Query] [nvarchar](MAX) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
) ON [PRIMARY]


这个,
txtQuerybox.text = txtQuerybox.text.Replace("''","'");


现在,在您的sql查询中传递"txtQuerybox.text"作为参数以保存/更新数据.

为什么会这样?
您在这样的文本框中有文字


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 ...')


有3个单引号,请参见带下划线的部分.
sql无法忽略值的结尾位置,因为启动&最终值由单引号&这里有3个单引号
祝您编码愉快!
:)


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!
:)


这篇关于有关数据库的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆