0
セッションオブジェクト型をintに変換しようとしていたときにこのエラーが発生しました。この値を使用する必要がありますデータ型intの別のクエリです。'System.Data.SqlClient.SqlDataReader'タイプのオブジェクトを 'System.IConvertible'に変換できません
SqlConnection sqlConnection1 = new SqlConnection("Persist Security Info=False;Integrated Security=true;Initial Catalog=Remember;server=DESKTOP-59SGH72\\SQLEXPRESS;Trusted_Connection=True;Database=sport");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = "select user_id from users where user_name='" + Session["usern"] + "'";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
reader = cmd.ExecuteReader();
Session["userid"] = reader;
var uid = Convert.ToInt16(Session["userid"]);
// Data is accessible through the DataReader object here.
sqlConnection1.Close();
このエラーで私を助けてください!
'Session [" userid "] = reader'は、これが読者の仕組みではない問題です。なぜそれはだと思いますか? – Hogan