Click here to Skip to main content
15,896,544 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have log in page with string cookies (username,password)in text box and (org) in drop down list
, i have a method create cookie and read from cookie

C#
public static string readFromCookie(string cookieName, string key, HttpRequest req)
   {
       try
       {

           //if (req.Cookies[cookieName] != null)

           return req.Cookies[cookieName][key].ToString();
       }
       catch
       {
           return null;
       }

   }




C#
public static void createCookie(string cookieName, string[] keys, string[] values, bool expierd, HttpResponse res)
   {
       //    HttpResponse res =new  HttpResponse();
       HttpCookie c = new HttpCookie(cookieName);
       if (keys != null)
       {
           for (int x = 0; x < keys.Length; x++)
               c.Values.Add(keys[x], values[x]);
           if (!expierd)
               c.Expires = DateTime.Now.AddYears(5);
       }
       else
           c.Expires = DateTime.Now.AddYears(-5);


       res.Cookies.Add(c);
   }




in code behind of target page :

public partial class user_user : System.Web.UI.Page
{
SqlCommand cmdd;
string _connStr = ConfigurationManager.ConnectionStrings["onlineSTR"].ConnectionString;

protected void Page_Load(object sender, EventArgs e)
{

string org = utility.readFromCookie("Login", "org", Request);
if (org != null)
{
//lbl.Text = Request.Cookies["org"].Value;
GetData(org);
}
}

private void GetData(string org)
{

DataTable table = new DataTable();
// get the connection
using (SqlConnection conn = new SqlConnection(_connStr))
{
// write the sql statement to execute
string sql = "SELECT orgName,orgID FROM organization WHERE orgName = @orgName ";
// instantiate the command object to fire
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
// get the adapter object and attach the command object to it
using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
{
SqlParameter prm = new SqlParameter("@orgName", SqlDbType.NVarChar);
prm.Value = org;
cmd.Parameters.Add(prm);
// fire Fill method to fetch the data and fill into DataTable
ad.Fill(table).ToString();
}
}
}

dv.DataSource = table;

dv.DataBind();

}
}


but the data it never bind, please tell me what is mistake.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900