I have cookies named empid which stores the id of employee i am going to use. But whenever i try to get the value of any cookie its value is set to null automatically and this code is from a partial class which is inherited by page . What if i want to create a class that contains all the database related code and want to use it in everypage
protected void Page_Load(object sender, EventArgs e)
{
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDbConn"].ToString()))
{
using (SqlCommand cmd = new SqlCommand())
{
try
{
cn.Open();
SqlDataReader conReader;
conReader = null;
mycomment.Text = Response.Cookies["empid"].Value;
// cmd.CommandText = "Select * from comments where c_from = " + Response.Cookies["cid"] + " and c_to = "+ Response.Cookies["empid"].ToString();
cmd.Connection = cn;
mycomment.Text = cmd.CommandText;
cmd.CommandType = CommandType.Text;
conReader = cmd.ExecuteReader();
while (conReader.Read())
{
mycomment.Text += conReader[3].ToString();
}
}
catch (Exception ex)
{
Console.Write(ex);
}
finally
{
cn.Close();
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire