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
public static string readFromCookie(string cookieName, string key, HttpRequest req)
{
try
{
return req.Cookies[cookieName][key].ToString();
}
catch
{
return null;
}
}
public static void createCookie(string cookieName, string[] keys, string[] values, bool expierd, HttpResponse res)
{
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.