入力されたコードが表にあるものと一致した場合、ユーザーの名前と電子メールアドレスを抽出するクエリがあります。コードは別のテーブルの主キーで、名前と電子メールテーブルの外部キーです。しかし、私はクエリを実行するたびに無効な列名 '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に値を連結する代わりに、パラメーターを使用する理由の1つです。もう1つはSQLインジェクション攻撃です。 – juharr