我有一个查询运行并应该提取用户的名称和电子邮件地址,如果输入的代码与表中找到的匹配。该代码是另一个表上的主键,并且是名称和电子邮件表上的外键。但是,每当我运行查询时,它都会返回无效的列名'a'。无效的列名称'a'
// the variable course runs through a method to capture the
// code from a textbox the user enters it in.
string sql = "select * from SI where Course= " + course;
SqlCommand command = new SqlCommand(sql, connection.con);
SqlDataReader read = command.ExecuteReader();
if (read.Read())
{
siname = read["Name"].ToString();
siemail = read["Email"].ToString();
}
read.Close();
是你的专栏当然是nvarchar? –
这是您应该使用参数而不是将值连接到SQL中的一个原因。另一个是SQL注入攻击。 – juharr