hi I have some text box and gridview in page that bind this gridview from database from Order table
now I want insert all textbox and grid view (all row) in data base in other table so I write below code:
protected void LBsabt_Click(object sender, EventArgs e)
{
using (SqlConnection conn = General.GetConnection())
{
using (SqlCommand _cmd = General.GetCommand("Order_Confirm", conn))
{
conn.Open();
foreach (DataRow row in gvOrders.Rows)
{
_cmd.Parameters.Clear();
_cmd.Parameters.AddWithValue("@Name", Txtname.Text);
_cmd.Parameters.AddWithValue("@Zone", Ddlzone.Text);
_cmd.Parameters.AddWithValue("@State", DdlState.Text);
_cmd.Parameters.AddWithValue("@City", DdlCity.Text);
_cmd.Parameters.AddWithValue("@Mobile", Txtmob.Text);
_cmd.Parameters.AddWithValue("@Tell", Txttell.Text);
_cmd.Parameters.AddWithValue("@PostCode", Txtcode.Text);
_cmd.Parameters.AddWithValue("@Address", Txtadd.Text);
_cmd.Parameters.AddWithValue("@Email", Txtemail.Text);
_cmd.Parameters.AddWithValue("@PostType", LblpostS.Text);
_cmd.Parameters.AddWithValue("@PriceTotal", Lblprice.Text);
_cmd.Parameters.AddWithValue("@PriceTotalBaste", Lblkol.Text);
_cmd.Parameters.AddWithValue("@PostPrice", LblPostT.Text);
_cmd.Parameters.AddWithValue("@Pcode", row["Pcode"]);
_cmd.Parameters.AddWithValue("@Ptype", row["Ptype"]);
_cmd.Parameters.AddWithValue("@PSectionName", row["PSectionName"]);
_cmd.Parameters.AddWithValue("@PName", row["PName"]);
_cmd.Parameters.AddWithValue("@OrderType", row["OrderType"]);
_cmd.Parameters.AddWithValue("@format", row["format"]);
_cmd.Parameters.AddWithValue("@Quantity", row["Quantity"]);
_cmd.Parameters.AddWithValue("@PriceP", row["PriceP"]);
_cmd.Parameters.AddWithValue("@PriceT", row["PriceT"]);
_cmd.ExecuteNonQuery();
}
}
}
}
but below error happen:
Unable to cast object of type 'System.Web.UI.WebControls.GridViewRow' to type 'System.Data.DataRow'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Web.UI.WebControls.GridViewRow' to type 'System.Data.DataRow'.
Source Error:
Line 60: conn.Open();
Line 61: //DataTable dtOrder = Session["Order"] as DataTable;
Line 62: foreach (DataRow row in gvOrders.Rows)
Line 63: {
Line 64: _cmd.Parameters.Clear();
|
Best regards
Neda