帮助更正具有查询stirng的sql语句. [英] help in correting the sql statment having query stirng.

查看:70
本文介绍了帮助更正具有查询stirng的sql语句.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码在productcatalog.aspx页面的基础上过滤数据


产品目录.aspx

i am filtering the data on the bases of productscatalog.aspx page using this code


Product Catalog.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ProductCatalog.aspx.cs" Inherits="ProductCatalog" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 

            onselectedindexchanged="GridView1_SelectedIndexChanged" Width="385px">
            <columns>
                <asp:TemplateField>
                    <itemtemplate>
                    
                        <table style="width: 100%">
                        <tr>
                            <td rowspan="4" valign="top" width="5%">
                                <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("ProductImage") %>' /></td>
                            <td align="left">
                                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("ProductID", "~/displayproduct.aspx?productid={0}") %>'

                                    Text='<%# Eval("ProductName") %>'></td>
                        </tr>
                        <tr>
                            <td align="left">
                                <asp:Label ID="Label3" runat="server" Text='<%# GetShortDescription(Eval("Description").ToString()) %>'></td>
                        </tr>
                        <tr>
                            <td align="left">
                                <asp:Label ID="Label5" runat="server" SkinID="FormLabel" Text="Price :">
                                <asp:Label ID="Label4" runat="server" Text='<%# Eval("UnitCost", "{0:C}") %>'></td>
                        </tr>
                        <tr>
                            <td align="right">
                                 </td>
                        </tr>
                    </table>
                    </itemtemplate>
                
            </columns>
        
    
    </div>
    </form>
</body>
</html>



产品catalog.cs文件为




product catalog.cs file is


 SqlConnection conn = new SqlConnection("Data Source=FAROOQPC\\SQLEXPRESS; Initial Catalog=ecommerce; Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            LoadGridView();

        }

    }
    private void LoadGridView()
    {
        //conn.Open();
        SqlDataAdapter da = new SqlDataAdapter("Select * from ESK_Products where CategoryID='"+Request.QueryString["CategoryID"]+"')", conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "mydb");
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind(); ;
        //conn.Close();
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected string GetShortDescription(string longdesc)
    {
        if (longdesc.Length <= 255)
        {
            return longdesc;
        }
        else
        {
            return longdesc.Substring(0, 255) + "...";
        }
    }
}




而且我有一个类别页面,该页面在datagrid vview中具有一个链接按钮,传递查询字符串






and i have the catgory page which has a linkbutton in datagrid vview passing the query string



<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 

            Width="124px">
            <columns>
                <asp:TemplateField>
                    <itemtemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" 

                            Text='<%# Eval("CategoryName") %>' PostBackUrl='<%#"~/ProductCatalog.aspx?ID="+Eval("CategoryID") %>'>
                    </itemtemplate>
                
            </columns>
            <emptydatatemplate>
                <asp:HyperLink ID="HyperLink1" runat="server" 

                    Text='<%# Eval("CatagoryName") %>'>
            </emptydatatemplate>
        
    
    </div>
    </form>
</body>
</html>




我在sqlquery中得到语法错误附近的错误)

任何人都可以解决..




i am getting the error in sqlquery that syntax error near )

can anyone figure it out..

推荐答案

为了上帝的缘故-使用Visual Studio随附的工具,在代码中放置一个try/catch块,并在调试器下运行它.
For god''s sake - use the tools that come with Visual Studio, put a try/catch block around your code, and run it under the debugger.


看看这一行:
look at this line :
SqlDataAdapter da = new SqlDataAdapter("Select * from ESK_Products where CategoryID=''"+Request.QueryString["CategoryID"]+"'')", conn);



它必须像:



It has to be like :

SqlDataAdapter da = new SqlDataAdapter("Select * from ESK_Products where CategoryID=''"+Request.QueryString["CategoryID"]+"''", conn);



如果您仔细观察,则会在末尾添加多余的)".

希望这能解决您的问题.
祝一切顺利.



If you observer closely, you have put redundant ")" at the end.

Hope this solved your problem.
All the best.


以此回复您的查询..

Replce your query with this..

SqlDataAdapter da = new SqlDataAdapter("Select * from ESK_Products where CategoryID=''"+Request.QueryString["CategoryID"]+"''", conn);



只需一个右括号.



Needed only one closing bracket..


这篇关于帮助更正具有查询stirng的sql语句.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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