fwsteal
asked on
query results into session variable
how do I put query results into session variable?
protected void btnLogin_Click(object sender, EventArgs e)
{
String strUserId = txtbxSiteCode.Text.ToStrin g();
String strPassword = txtbxPassword.Text.ToStrin g();
if (ValidateUser(strUserId, strPassword))
{
//generate a session variable
SqlCommand cmd = new SqlCommand("uspGetCIDFKByS iteCode", new SqlConnection(myConn));
cmd.CommandType = System.Data.CommandType.St oredProced ure;
cmd.Parameters.AddWithValu e("@SiteCo de", strUserId);
cmd.Connection.Open();
SqlDataReader rdr = cmd.ExecuteReader();
cmd.Connection.Close();
cmd.Connection.Dispose();
//something like?
//Session["CIDFK"] = Convert.ToInt32(CIDFK.fiel dvalue);
//how do I put the value into a session like this? Session["CIDFK"] = 30; where the cidfk is an interger
FormsAuthentication.Redire ctFromLogi nPage(strU serId, false);
Response.Redirect("audit/d efault.asp x");
//I read that SqlDataReader would do what you want it to and work great for single table returns.
//You can store them to session variables and access the elements.
//how is this achieved?
}
else
{
Response.Redirect("login.a spx", true);
}
}
I'm just not sure how to do it.
protected void btnLogin_Click(object sender, EventArgs e)
{
String strUserId = txtbxSiteCode.Text.ToStrin
String strPassword = txtbxPassword.Text.ToStrin
if (ValidateUser(strUserId, strPassword))
{
//generate a session variable
SqlCommand cmd = new SqlCommand("uspGetCIDFKByS
cmd.CommandType = System.Data.CommandType.St
cmd.Parameters.AddWithValu
cmd.Connection.Open();
SqlDataReader rdr = cmd.ExecuteReader();
cmd.Connection.Close();
cmd.Connection.Dispose();
//something like?
//Session["CIDFK"] = Convert.ToInt32(CIDFK.fiel
//how do I put the value into a session like this? Session["CIDFK"] = 30; where the cidfk is an interger
FormsAuthentication.Redire
Response.Redirect("audit/d
//I read that SqlDataReader would do what you want it to and work great for single table returns.
//You can store them to session variables and access the elements.
//how is this achieved?
}
else
{
Response.Redirect("login.a
}
}
I'm just not sure how to do it.
Session["CIDFK"] = CIDFK.fieldvalue.ToString( );
ASKER
how do I determine if the session variable is empty or null?
protected void Page_Load(object sender, EventArgs e)
{
if (Session["CIDFK"] == "")
{
Response.Redirect("../defa ult.aspx", true);
}
//set the title of the page
this.Title = SiteConfiguration.SiteName ;
String mystring = Session["CIDFK"].ToString( );
Response.Write(mystring);
protected void Page_Load(object sender, EventArgs e)
{
if (Session["CIDFK"] == "")
{
Response.Redirect("../defa
}
//set the title of the page
this.Title = SiteConfiguration.SiteName
String mystring = Session["CIDFK"].ToString(
Response.Write(mystring);
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
had to do this to get it to work:
string CIDFK = null;
/// check for existance of the session variable
if (Session["CIDFK"] != null)
{
CIDFK = Session["CIDFK"].ToString( );
}
if (CIDFK == null)
{
Response.Redirect("../defa ult.aspx", true);
}
string CIDFK = null;
/// check for existance of the session variable
if (Session["CIDFK"] != null)
{
CIDFK = Session["CIDFK"].ToString(
}
if (CIDFK == null)
{
Response.Redirect("../defa
}