私はASP.NET C#を初めて使用しています。メッセージを送受信するためのWebフォームの開発に取り組んでいます。電子メールのように。私はSQLクエリの結果をセッション変数に保存し、後で別のページで使用したいと思います。ASP.NET C#を使用してセッション変数にSQLクエリの結果を格納する方法
どうすればいいのですか。何か問題が生じた場合は、どうか修正してください。あなたはあなたを返します。このメソッドにそのクエリを渡す必要が
SqlConnection con = new SqlConnection("Data Source=AZEEM\\SQLEXPRESS; Initial Catalog=kics;User ID=sa;Password=123");
con.Open();
String query = "select username as sender,subject,message from emailtable where receiver='" + Session["username"] + "'";
enter code here
//this is the query for which I want to store the result in variable myvar, how can I store the result of following query in variable myvar and use it later, when I execute it, string is shown instead of result of string.
String myvar = "select receiver from emailtable where username='" + Session["username"] + "'";
SqlDataReader reader = null;
SqlCommand cmd = new SqlCommand(query, con);
SqlCommand cmd2 = new SqlCommand(myvar, con);
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
reader = cmd2.ExecuteReader();
GridView1.DataSource = dt;
GridView1.DataBind();
DataSet ds = new DataSet();
ds = myvar;
を次のように、私は変数MYVARで次のクエリの結果を保存したい、実際 – Webruster
以上を明確に、文字列のMYVARは=「から受信機を選択しますemailtable username = '"+ Session [" username "] +"' ";私はそれを行う方法を知らない、このクエリの結果をチェックするとき、それは私にクエリ文字列を与えるが、私はクエリの結果が欲しい。 –