-3

我正在使用此代码,在运行代码时出现错误。

where 子句附近的语法不正确。

这是我的 C# 代码:

SqlConnection con = new SqlConnection("Data Source=ANURAG-PC;Initial Catalog=dbPortal;Persist Security Info=True;User ID=yyyy;Password=xxxxx");

protected void Page_Load(object sender, EventArgs e) 
{
   if (IsPostBack == false)
   {
       string s = Request.QueryString["cat"];
       string s1 = Request.QueryString["sub"];

       SqlCommand cmd = new SqlCommand("Select * from Architect where where SubCategory1 = @sub1",con);
       cmd.Parameters.AddWithValue("@sub1", s1);

       con.Open();

       using (SqlDataReader reader = cmd.ExecuteReader())
       {
           DataTable dat = new DataTable("tab");
           dat.Load(reader);
           DataGrid1.DataSource = dat;
           DataGrid1.DataBind();
       }
    }
}

有什么问题吗?

4

2 回答 2

2

看看查询 - 你where where有。应该只有一个where

SqlCommand cmd = 
    new SqlCommand("Select * from Architect where where SubCategory1=@sub1",con);

应该:

SqlCommand cmd = 
    new SqlCommand("Select * from Architect where SubCategory1=@sub1",con);
于 2012-07-04T19:14:58.173 回答
1

你好正确删除where,你有两个where

SqlCommand cmd = new SqlCommand("Select * from Architect where where SubCategory1=@sub1",con);

-> SqlCommand cmd = new SqlCommand("Select * from Architect where SubCategory1=@sub1",con);
于 2012-07-04T19:15:22.593 回答