帮助更正具有查询stirng的sql语句.

编程入门 行业动态 更新时间:2024-10-11 17:29:36
本文介绍了帮助更正具有查询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" "www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="www.w3/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" "www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="www.w3/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语句.

本文发布于:2023-11-22 06:11:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616269.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   stirng   sql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!