hi
I have two page in first page when click button it will save data in session below is code:
protected void Imgorder_Click(object sender, EventArgs e)
{
ImageButton ibtn = sender as ImageButton;
int id = Convert.ToInt32(Request.QueryString["Id"].ToString());
DataTable dtFiles = GetFilmInfo(id);
string Name = dtFiles.Rows[0][1].ToString();
string MKVE = dtFiles.Rows[0][37].ToString();
string DVDE = dtFiles.Rows[0][38].ToString();
string PostMkvPr = dtFiles.Rows[0][12].ToString();
string PostDvdPr = dtFiles.Rows[0][13].ToString();
string Code = dtFiles.Rows[0][4].ToString();
string Type = dtFiles.Rows[0][36].ToString();
string SectionName = dtFiles.Rows[0][3].ToString();
DataTable dt = new DataTable();
if (Session["Order"] != null)
{
dt = Session["Order"] as DataTable;
}
else
{
dt.Columns.AddRange(new DataColumn[] { new DataColumn("Id",typeof(int)),new DataColumn("Name",typeof(string)),new DataColumn("Quality",typeof(string)),
new DataColumn("PriceT", typeof(decimal)), new DataColumn("Price", typeof(decimal)), new DataColumn("Quanyity", typeof(int)),new DataColumn("code",typeof(string)),new DataColumn("Type",typeof(string))
,new DataColumn("SectionName",typeof(string)),
new DataColumn("buy",typeof(string)),new DataColumn("show",typeof(string)),});
}
if (RBmkv.Checked || RBdvd.Checked)
{
if (RBmkv.Checked)
{
DataRow duplicate = (from d in dt.AsEnumerable()
where d.Field<string>("Quality") == "MKV"
&& d.Field<string>("Name") == Name
select d).FirstOrDefault();
if (duplicate != null)
{
int qty = Convert.ToInt32(duplicate.ItemArray[5]);
duplicate["Quanyity"] = (qty + 1);
duplicate["PriceT"] = (int.Parse(PostMkvPr) * (qty + 1));
dt.AcceptChanges();
}
else
{
dt.Rows.Add(dt.Rows.Count + 1, Name, "MKV", PostMkvPr, PostMkvPr, MKVE, Code, Type, SectionName, "خرید پستی", "Buy");
}
}
if (RBdvd.Checked)
{
DataRow duplicate = (from d in dt.AsEnumerable()
where d.Field<string>("Quality") == "DVD" && d.Field<string>("Name") == Name
select d).FirstOrDefault();
if (duplicate != null)
{
int qty = Convert.ToInt32(duplicate.ItemArray[5]);
duplicate["Quanyity"] = (qty + 1);
duplicate["PriceT"] = (int.Parse(PostDvdPr) * (qty + 1));
dt.AcceptChanges();
}
else
{
dt.Rows.Add(dt.Rows.Count + 1, Name, "DVD", PostDvdPr, PostDvdPr, DVDE, Code, Type, SectionName, "خرید پستی", "Buy");
}
int totalOrder = dt.AsEnumerable().Sum(row => row.Field<int>("Quanyity"));
Lblorder.Text = totalOrder.ToString();
Response.Cookies["UserName"].Value = Lblorder.Text.Trim();
}
}
}
it will save data in session in some rows like below:
Id
|
Name
|
Code
|
Type
|
sectionname
|
1
|
India
|
1000
|
Documentry
|
First
|
2
|
WaterFall
|
1023
|
Film
|
Down
|
|
|
|
|
|
now in other page I wrote some code that I want it will save session valuse in database:
protected void LBsabt_Click(object sender, EventArgs e)
{
using (SqlConnection conn = General.GetConnection())
{
using (SqlCommand _cmd = General.GetCommand("Oreder_Insert", conn))
{
DataTable dtOrder = Session["Order"] as DataTable;
conn.Open();
_cmd.Parameters.AddWithValue("@UserName", LblName.Text);
_cmd.Parameters.AddWithValue("@Mobile", LblMob.Text);
_cmd.Parameters.AddWithValue("@Tell", LblTell.Text);
_cmd.Parameters.AddWithValue("@code", dtOrder.Rows[0]["Code"]);
_cmd.Parameters.AddWithValue("@type", dtOrder.Rows[0]["Type"]);
_cmd.Parameters.AddWithValue("@SectionName", dtOrder.Rows[0]["SectionName"]);
_cmd.Parameters.AddWithValue("@Name", dtOrder.Rows[0]["Name"]);
_cmd.ExecuteNonQuery();
}
}
}
now here it will save session["oreder"] values in database but one row of it I mean it just save below info from above table(just one row of data):
Id
|
Name
|
Code
|
Type
|
sectionname
|
Username
|
Mobile
|
Tell
|
2
|
WaterFall
|
1023
|
Film
|
Down
|
Nead
|
123456
|
123356
|
but I want it will save all data from session:
Like below:
Id
|
Name
|
Code
|
Type
|
sectionname
|
Username
|
Mobile
|
Tell
|
1
|
India
|
1000
|
Documentry
|
First
|
Neda
|
123456
|
123356
|
2
|
WaterFall
|
1023
|
Film
|
Down
|
Neda
|
123456
|
123356
|
Best Regards
Neda