小编use*_*598的帖子

"'附近的语法不正确

这是代码背后的页面,它有错误

if (Session["username"] != null)
   {


        SqlConnection con = new SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["registerCS"].ConnectionString;

       string sql1 = "Select pemgrp from Profile where userID = '" + Session["username"].ToString() + "'";
      string sql = "Select studname from Profile where pemgrp = '" + sql1 + "'";

        SqlCommand cmd = new SqlCommand();
        SqlDataReader dr;

        DataTable dt = new DataTable();

        cmd.CommandText = sql;
        cmd.Connection = con;

        //open connection and execute command
        con.Open();
        dr = cmd.ExecuteReader();

        if (dr.Read())
        {
        lb_classmates.Text = dr[0].ToString();

        }
    }
Run Code Online (Sandbox Code Playgroud)

但是,当我运行时,它给我这个错误:关键字'where'附近的语法不正确. …

c# sql asp.net

2
推荐指数
1
解决办法
294
查看次数

不包含定义定义

在我宣布这个之后,这就是我得到的错误

protected void Page_Load(object sender, EventArgs e)
{
        List<String> LabelTextList = new List<String>();
         dr = cmd.ExecuteReader();
        while (dr.Read())
        {
        LabelTextList.add(dr[0].ToString());
        }
 }
Run Code Online (Sandbox Code Playgroud)

错误1"MasterPage_Profile"不包含"LabelTextList"的定义,并且没有可以找到接受"MasterPage_Profile"类型的第一个参数的扩展方法"LabelTextList"(您是否缺少using指令或程序集引用?)

[更新]现在它说:

'System.Collections.Generic.List'不包含'add'的定义,也没有扩展方法'add'接受类型为'System.Collections.Generic.List'的第一个参数'(你是否缺少using指令)或汇编参考?)

c#

1
推荐指数
1
解决办法
1718
查看次数

标签 统计

c# ×2

asp.net ×1

sql ×1