Asp.net 运行时异常“=”附近的语法不正确

Asp.net 运行时异常“=”附近的语法不正确,asp.net,Asp.net,当我试图回复帖子时,收到一个sqlexception。错误:靠近“=”的语法不正确。我环顾四周,寻找其他类似的问题,但我找不到任何对我有价值的东西 我在da.fillds;上遇到错误;。任何人都可以在这方面帮助我……:查询字符串中的postid可能没有值,因此TSQL语句无效 添加是否提供查询字符串值的检查 也验证它的值在您预期的范围内,并考虑使用准备好的语句/参数——您当前的方法使您对SQL注入开放。Posid从查询字符串中可能没有值,因此TSQL语句无效。 添加是否提供查询字符串值的检查 也

当我试图回复帖子时,收到一个sqlexception。错误:靠近“=”的语法不正确。我环顾四周,寻找其他类似的问题,但我找不到任何对我有价值的东西

我在da.fillds;上遇到错误;。任何人都可以在这方面帮助我……:

查询字符串中的postid可能没有值,因此TSQL语句无效

添加是否提供查询字符串值的检查

也验证它的值在您预期的范围内,并考虑使用准备好的语句/参数——您当前的方法使您对SQL注入开放。

Posid从查询字符串中可能没有值,因此TSQL语句无效。

添加是否提供查询字符串值的检查

也验证它的值在您预期的范围内,并考虑使用准备好的语句/参数——您当前的方法使您对SQL注入开放。

< P>您的POSITD是一个字符串,它应该用单引号“

”括起来。 但如果你用它来拯救自己,那就更好了

比如:

您的posted是一个字符串,应该用单引号括起来'

但如果你用它来拯救自己,那就更好了

比如:


你有没有按照其中一个答案中的建议尝试过以下内容

替换字符串sql=select*from Forumthread,其中PostID=+PostID

使用字符串sql=select*fromForumThread,其中PostID='+PostID+'

或:

若它不起作用,那个么可能您将不得不在查询中直接使用int。 为此,只需在整数变量中获取queryString值。 比如:


你有没有按照其中一个答案中的建议尝试过以下内容

替换字符串sql=select*from Forumthread,其中PostID=+PostID

使用字符串sql=select*fromForumThread,其中PostID='+PostID+'

或:

若它不起作用,那个么可能您将不得不在查询中直接使用int。 为此,只需在整数变量中获取queryString值。 比如:


postid的值是多少?postid的值是多少?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="postreplyadmin.aspx.cs" Inherits="postreplay" MasterPageFile="~/AdminMaster.master" Title="Post-Reply Page"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<%
    String postid = Request.QueryString["id"];
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["civilRegDB"].ConnectionString);
    con.Open();
    String sql = "select * from Forumthread where PostID=" + postid;
    SqlDataAdapter da=new SqlDataAdapter(sql,con);        
    DataSet ds=new DataSet();
    da.Fill(ds);
    DataRow drow = ds.Tables[0].Rows[0];
    String name = drow["Name"].ToString();
    String desc = drow["Description"].ToString();
    DateTime dt = Convert.ToDateTime(drow["PostDate"].ToString());
    String postdate = dt.ToString("dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture );
    String mailid = drow["Email"].ToString();
    %>
</asp:content>
String sql = "select * from Forumthread where PostID='" + postid +"'";
String postid = Request.QueryString["id"];
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["civilRegDB"].ConnectionString);
con.Open();
String sql = "select * from Forumthread where PostID=@postID"; //parameter
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("postID", postid);
SqlDataAdapter da = new SqlDataAdapter(cmd); // pass command to adapter
DataSet ds = new DataSet();
da.Fill(ds);
DataRow drow = ds.Tables[0].Rows[0];
String name = drow["Name"].ToString();
String desc = drow["Description"].ToString();
DateTime dt = Convert.ToDateTime(drow["PostDate"].ToString());
String postdate = dt.ToString("dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
String mailid = drow["Email"].ToString();
int postid = Convert.ToInt32(Request.QueryString["id"]);
String sql = "select * from Forumthread where PostID=" + postid;