c# - 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);
}
}
我检查了所有的名字,它们都很好。
我不知道现在该怎么办!
解决方案
使用字符串引号
String SQL = string.Format("select ID from dbo.details where email='{0}'", S1 );
推荐阅读
- python - 仅当条目不存在时才将条目添加到数据库的正确方法;使用 python + peewee
- c - 通过静态库链接时功能无法正常工作,但如果在 prog 中复制则可以正常工作
- python - 将列表转换为单独的数据框
- python - 如何导入csv并访问表格数据?
- javascript - ReactiveForms:输入类型“文件”由 addControl() 重置
- php - OKTA SSO 验证显示无效 URL
- apache-kafka - 我可以把这个“max.task.idle.ms”放在哪个配置文件中?
- server - Dovecot,后缀 - 无法接收到我的服务器的任何电子邮件
- python - 关于 QPixmap 改变不透明度
- python - 如何在 Pandas 时间序列中为每一行获得延迟到期之前的最后一个值?