我有一個查詢運行並應該提取用戶的名稱和電子郵件地址,如果輸入的代碼與表中找到的匹配。該代碼是另一個表上的主鍵,並且是名稱和電子郵件表上的外鍵。但是,每當我運行查詢時,它都會返回無效的列名'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