error
Input string was not in a correct format.
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.FormatException: Input string was not in a correct format.
Source Error:
Line 59: Primarykey = Convert.ToInt32(GridView2.DataKeys[i].Value);
Line 60: ProductName = ((Label)GridView2.Rows[i].FindControl("lblproductname")).Text;
Line 61: txtCostPrice = Convert.ToInt32(((TextBox)GridView2.Rows[i].FindControl("txtcostprice")).Text);
Line 62:
my code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class About : System.Web.UI.Page
{
string dbcon = ConfigurationManager.ConnectionStrings["strislamic"].ConnectionString;
SqlConnection con;
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
public void bind()
{
con = new SqlConnection(dbcon);
con.Open();
SqlCommand cmd = new SqlCommand("Select * from studentF1 where grade='" +"الاول - G1"+"' and section='"+"هـ - E"+"'", con);
da.SelectCommand = cmd;
ds = new DataSet();
da.Fill(ds, "studentF1");
GridView2.DataSource = ds.Tables["studentF1"].DefaultView;
GridView2.DataBind();
con.Close();
}
public void savedata()
{
con = new SqlConnection(dbcon);
con.Open();
int txtCostPrice = 0;
int Primarykey = 0;
string ProductName = "";
DataTable dt = new DataTable();
dt.Columns.Add("idsd", typeof(int));
dt.Columns.Add("aname", typeof(string));
dt.Columns.Add("qi1", typeof(int));
//dt.Columns.Add("qi2", typeof(int));
da = new SqlDataAdapter("Select * from studentF1", con);
SqlCommandBuilder cmb = new SqlCommandBuilder(da);
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
ds = new DataSet();
da.Fill(ds, "studentF1");
for (int i = 0; i < GridView2.Rows.Count; i++)
{
Primarykey = Convert.ToInt32(GridView2.DataKeys[i].Value);
ProductName = ((Label)GridView2.Rows[i].FindControl("lblproductname")).Text;
here error (note my field qi1 decimal(8,1)
txtCostPrice = Convert.ToInt32(((TextBox)GridView2.Rows[i].FindControl("txtcostprice")).Text);
DataRow dr = ds.Tables["studentF1"].Rows[i];
if (txtCostPrice.Equals(string.Empty))
dr["qi1"] = 0;
else
dr["qi1"] = txtCostPrice;
da.Update(ds, "studentF1");
}
con.Close();
bind();
}
protected void btnupdate_Click(object sender, EventArgs e)
{
savedata();
}
}