初学者求助,谢谢。可能是SQL语句错误。
VS210 参照某书的代码做一个网站
按照它的方法建了个公共类BaseClass处理数据
这是其中用到的一个方法
然后在展示信息的页面时,运行后报错指向上面的方法的Cmd.Fill(dt)处
提示“用户代码未处理,SqlException 关键字 'user' 附近有语法错误。”
传参过来的前一页的传参代码 是从Gridview的一项中的超链接过来的
这是问题页面
前
后
做相似的另一个功能时,几乎用了同样的代码可以运行,就这里边的这句SQL语句因为查询的表不同而有不同
直接用request.querystring["id"]也不行,求解,谢谢
另外数据库的表 user 和 comment 以及故障图


报错图

按照它的方法建了个公共类BaseClass处理数据
这是其中用到的一个方法
//读写数据表--DataTable
public DataTable ReadTable(String strSql)
{
DataTable dt=new DataTable();//创建一个数据表dt
SqlConnection Conn = new SqlConnection(strConn);//定义新的数据连接控件并初始化
Conn.Open();//打开连接
SqlDataAdapter Cmd = new SqlDataAdapter(strSql, Conn);//定义并初始化数据适配器
Cmd.Fill(dt); //将数据适配器中的数据填充到数据集dt中
Conn.Close();//关闭连接
return dt;
}然后在展示信息的页面时,运行后报错指向上面的方法的Cmd.Fill(dt)处
提示“用户代码未处理,SqlException 关键字 'user' 附近有语法错误。”
传参过来的前一页的传参代码 是从Gridview的一项中的超链接过来的
<asp:HyperLinkField DataNavigateUrlFields="userid" DataNavigateUrlFormatString="profile.aspx?id={0}"
DataTextField="username" DataTextFormatString="·{0}" HeaderText="username">这是问题页面
前
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true" CodeFile="profile.aspx.cs" Inherits="profile" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:DataList ID="DataList1" runat="server" RepeatColumns="1" Font-Bold="False"
Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" HorizontalAlign="Center">
<FooterStyle BackColor="Silver" Font-Bold="False" Font-Italic="False"
Font-Names="楷体" Font-Overline="False" Font-Size="Larger" Font-Strikeout="False"
Font-Underline="False" ForeColor="Red" HorizontalAlign="Justify"
VerticalAlign="Bottom" />
<HeaderStyle BackColor="Lime" Font-Bold="False" Font-Italic="False"
Font-Names="华文楷体" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" ForeColor="Blue" HorizontalAlign="Center"
VerticalAlign="Middle" />
<ItemTemplate>
<table style="width: 100%">
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "userid")%> </td>
</tr>
</table>
<table style="width: 100%">
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "username")%> </td>
</tr>
</table>
<table style="width: 100%">
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "userinfo")%></td>
</tr>
</table>
</table>
<table style="width: 100%">
<tr>
<td>
<a href='mycomments.aspx?id=<%# DataBinder.Eval(Container.DataItem, "articleid")%>'>
<%# DataBinder.Eval(Container.DataItem, "userid")%><a/>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</asp:Content>
后
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GROUP.Manage;
using System.Data;
public partial class profile : System.Web.UI.Page
{
BaseClass BaseClass1 = new BaseClass();
protected void Page_Load(object sender, EventArgs e)
{
string strsql = "select * from user where userid=" + Request.Params["id"].ToString();
DataTable dt = BaseClass1.ReadTable(strsql);
DataList1.DataSource = dt;
DataList1.DataBind();
}
}做相似的另一个功能时,几乎用了同样的代码可以运行,就这里边的这句SQL语句因为查询的表不同而有不同
直接用request.querystring["id"]也不行,求解,谢谢
另外数据库的表 user 和 comment 以及故障图

报错图

...全文
相关推荐
Oracle Sql语句转换成Mysql Sql语句
它通过自动化处理减少了手动转换的工作量,降低了错误率,有助于提高项目迁移的效率和质量。
Sql语句自动生成器
此外,对于高级用户,可能还支持自定义模板和宏,以便于适应不同的数据库系统和特定需求。总结来说,SQL语句自动生成器是提高数据库管理效率、降低错误率的有效工具。
VB运用SQL语句读取显示数据库中的数据
你可以使用VB的On Error语句来设置错误处理机制。通过以上步骤,你就可以在VB中使用SQL语句从Access数据库中读取和显示数据了。
SQL UPDATE 语句
总的来说,SQL UPDATE 语句是数据库操作中不可或缺的一部分,它允许我们动态地维护数据库中的信息,但同时也需要我们谨慎使用,以避免潜在的数据错误。
常用Sql注入语句 常用Sql注入语句
Error Handling:正确处理错误信息,避免泄露敏感信息。常用 Sql 注入语句:1.


