私はうまく動作しているショッピングカートを持っていますが、ユーザーが注文しないと、ログアウト後にカートアイテムが残っていません。誰でもカートアイテムを少なくとも1日間はいかにしておくかを教えてください。私は私が行っているしたいですここでは、任意のデータベースを使用していない:カートのアイテムをログアウトしてから24時間ご利用いただけますか?
if (!IsPostBack)
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add("sno");
dt.Columns.Add("Game_Name");
dt.Columns.Add("Platform");
dt.Columns.Add("Price");
dt.Columns.Add("Quantity");
dt.Columns.Add("Image");
dt.Columns.Add("cost");
dt.Columns.Add("totalcost");
//BindGridView();
if (Request.QueryString["Game_ID"] != null)
{
if (Session["Buyitems"] == null)
{
dr = dt.NewRow();
String mycon = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True";
SqlConnection scon = new SqlConnection(mycon);
String myquery = "select * from Game where Game_ID=" + Request.QueryString["Game_ID"];
SqlCommand cmd = new SqlCommand();
cmd.CommandText = myquery;
cmd.Connection = scon;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
dr["sno"] = 1;
dr["Game_Name"] = ds.Tables[0].Rows[0]["Game_Name"].ToString();
dr["Platform"] = ds.Tables[0].Rows[0]["Platform"].ToString();
dr["Image"] = ds.Tables[0].Rows[0]["Image"].ToString();
dr["Price"] = ds.Tables[0].Rows[0]["Price"].ToString();
dr["Quantity"] = ds.Tables[0].Rows[0]["Quantity"].ToString();
dt.Rows.Add(dr);
GridView1.DataSource = dt;
GridView1.DataBind();
Session["buyitems"] = dt;
}
else
{
dt = (DataTable)Session["buyitems"];
int sr;
sr = dt.Rows.Count;
dr = dt.NewRow();
String mycon = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True";
SqlConnection scon = new SqlConnection(mycon);
String myquery = "select * from Game where Game_ID=" + Request.QueryString["Game_ID"];
SqlCommand cmd = new SqlCommand();
cmd.CommandText = myquery;
cmd.Connection = scon;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
dr["sno"] = sr + 1;
dr["Game_Name"] = ds.Tables[0].Rows[0]["Game_Name"].ToString();
dr["Platform"] = ds.Tables[0].Rows[0]["Platform"].ToString();
dr["Image"] = ds.Tables[0].Rows[0]["Image"].ToString();
dr["Price"] = ds.Tables[0].Rows[0]["Price"].ToString();
dr["Quantity"] = ds.Tables[0].Rows[0]["Quantity"].ToString();
dt.Rows.Add(dr);
GridView1.DataSource = dt;
GridView1.DataBind();
Session["buyitems"] = dt;
}
}
else
{
dt = (DataTable)Session["buyitems"];
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
と私は、前のページから各ゲームのIDを取得するために、コマンド引数を使用してメートル。
あなたはログアウトした後、ユーザーがログインしたと仮定して、カートをアカウントにバインドするだけです。 cartやcartToProductなどのデータベーステーブルを作成し、カートに有効期限を設定するだけです – EpicKip