hi
in NewOrder.aspx page is gridview that bind from database and button that insert gridview's rows data into other table in database:
below are codes:
protected void LBsabt_Click(object sender, EventArgs e)
{
int data1 = Convert.ToInt32(Request.QueryString["PeygiriCode"].ToString());
using (SqlConnection conn = General.GetConnection())
{
using (SqlCommand _cmd = General.GetCommand("OrderC_Insert", conn))
//using (SqlCommand _cmd = General.GetCommand("OrderConfirm_Insert", conn))
{
conn.Open();
foreach (GridViewRow row in gvOrders.Rows)
{
_cmd.Parameters.Clear();
string Pcode = (row.FindControl("LblPcode") as Label).Text.Trim();
string OrderType = (row.FindControl("LblOrderType") as Label).Text.Trim();
string format = (row.FindControl("LblFormat") as Label).Text.Trim();
string Ptype = (row.FindControl("LblPtype") as Label).Text.Trim();
string PSectionName = (row.FindControl("LblPSectionName") as Label).Text.Trim();
string PName = (row.FindControl("LblName") as Label).Text.Trim();
string PriceT = (row.FindControl("LblPriceT") as Label).Text.Trim();
string Date = (row.FindControl("lblDate") as Label).Text.Trim();
string Time = (row.FindControl("Lbltime") as Label).Text.Trim();
_cmd.Parameters.AddWithValue("@time", Time);
_cmd.Parameters.AddWithValue("@Date", Date);
_cmd.Parameters.AddWithValue("@Name", Txtname.Text);
_cmd.Parameters.AddWithValue("@State", DdlState.SelectedItem.Text);
_cmd.Parameters.AddWithValue("@City", DdlCity.SelectedItem.Text);
_cmd.Parameters.AddWithValue("@Address", Txtadd.Text);
_cmd.Parameters.AddWithValue("@Pcode", Pcode);
_cmd.Parameters.AddWithValue("@Email", Txtemail.Text);
_cmd.Parameters.AddWithValue("@Mobile", Txtmob.Text);
_cmd.Parameters.AddWithValue("@Tell", Txttell.Text);
_cmd.Parameters.AddWithValue("@Ptype", Ptype);
_cmd.Parameters.AddWithValue("@PostCode", Txtcode.Text);
_cmd.Parameters.AddWithValue("@PName", PName);
_cmd.Parameters.AddWithValue("@PSectionName", PSectionName);
_cmd.Parameters.AddWithValue("@format", format);
_cmd.Parameters.AddWithValue("@OrderType", OrderType);
_cmd.Parameters.AddWithValue("@PriceT", PriceT);
_cmd.Parameters.AddWithValue("@PriceTotal", Lblprice.Text);
_cmd.Parameters.AddWithValue("@PriceTotalBaste", Lblkol.Text);
_cmd.Parameters.AddWithValue("@PostType", LblpostS.Text);
_cmd.Parameters.AddWithValue("@Zone", Ddlzone.SelectedItem.Text);
_cmd.Parameters.AddWithValue("@PostPrice", LblPostT.Text);
_cmd.Parameters.AddWithValue("@Peygiricode", data1);
_cmd.ExecuteNonQuery();
Response.Redirect("NewOrder.aspx");
}
}
}
}
and SP:
INSERT INTO Order_Confirm
(Name,[State] ,City,Address,PCode,Email ,Mobile ,Tell ,PType ,PostCode,PName,PSectionName
,Format,OrderType,PriceT ,PriceTotal,PostType,PriceTotalBaste,zone ,PostPrice,PeygiriCode,date,time,sefaresh)
VALUES
(@Name,@State ,@City,@Address,@PCode,@Email ,@Mobile ,@Tell ,@PType ,@PostCode,@PName ,@PSectionName
,@Format,@OrderType,@PriceT ,@PriceTotal ,@PostType,@PriceTotalBaste,@Zone,@PostPrice,@Peygiricode,@date,@time,'تایید')
but when I click on button it just insert gridview's first row into table I want it insert all row of gridview in table ...
where is problem?
Best regards
neda