gpt4 book ai didi

c# - 查询中的“条件是预期的”

转载 作者:行者123 更新时间:2023-11-30 18:54:49 25 4
gpt4 key购买 nike

SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\Projects\\csharp\\Login1\\App_Data\\Login.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd;
SqlDataReader dr;

protected void LinkButton1_Click(object sender, EventArgs e)
{
conn.Open();
cmd=new SqlCommand("Select * from LoginTable where User Name='"+TextBox1.Text+"'",conn);
dr=cmd.ExecuteReader(); // <---error here

if(dr.Read())
{
Label1.Text="User name already exist";
this.Label1.ForeColor=Color.Red;
}
else
{
Label1.Text="Name available";
}
}

它在 dr=cmd.ExecuteReader(); 附近显示以下错误:

An expression of non-boolean type specified in a context where a condition is expected, near 'Name'.

这里发生了什么

最佳答案

将where子句中的User Name替换为[User Name]

关于c# - 查询中的“条件是预期的”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16806605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com