首页 > 解决方案 > asp.net '无法绑定多部分标识符“abc@gmail.com”。'

问题描述

我编写了一些代码来dbo.details使用存储在会话中的用户电子邮件 id 来访问 id 表单表,但是我收到了这个错误

无法绑定多部分标识符“abc@gmail.com”

我使用了 Visual Studio 2017 的内置服务器。

这是我的代码:

protected void Page_Load(object sender, EventArgs e)
{
        if (Session["user"] == null)
        {
            Response.Write("<script>alert('you have to login to Checkout!')</script>");
            Response.Redirect("login.aspx");
        }
        else
        {
            string S1 = Convert.ToString(Session["user"].ToString());

            SqlConnection scon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            String myquery = "select ID from dbo.details where email=" + S1;

            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = myquery;
            cmd.Connection = scon;

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;

            DataSet ds = new DataSet();
            da.Fill(ds);

            int details_id = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
            Response.Write(details_id);
        }
}

我检查了所有的名字,它们都很好。

我不知道现在该怎么办!

标签: c#sqlasp.netsql-server

解决方案


使用字符串引号

 String SQL = string.Format("select ID from dbo.details where email='{0}'", S1 );

推荐阅读