【发布时间】:2013-12-01 07:37:43
【问题描述】:
当我执行下面的代码时,会出现此错误消息:
“'System.Data.SqlClient.SqlException' 类型的异常发生在 System.Data.dll 但未在用户代码中处理
附加信息:“=”附近的语法不正确。 "
这是代码:
string position;
SqlConnection con = new SqlConnection("server=free-pc\\FATMAH; Integrated Security=True; database=Workflow; ");
con.Open();
SqlCommand cmd = new SqlCommand("SELECT EmpName FROM Employee WHERE EmpID=" + id.Text, con);
SqlDataReader Read = cmd.ExecuteReader();
if (Read.Read()==true)
{
position = Read[0].ToString();
Response.Write("User Registration successful");
}
else
{
Console.WriteLine("No Employee found.");
}
Read.Close();
这是什么原因造成的,我该如何解决?
【问题讨论】:
-
id
TextBox提供的文字是什么? -
不要将输入连接到 SQL 中非常重要。使用参数。否则,它要么只是偶尔失败(希望你的公司没有
O'Neil),要么会充当安全漏洞(参见:“bobby tables”)
标签: c# .net sql sql-server visual-studio-2013