I'm trying to retrieve a data from a table and subtract it to another variable, but I'm getting this error Input string was not in a correct format.
Here is my code:
SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString);
DataTable dt = new DataTable();
con1.Open();
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("SELECT Cash from Sales where SalesID='" + GridView2.Rows[0].Cells[0].Text+"'", con1);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
TextBox3.Text = myReader["Cash"].ToString();
TextBox4.Text = (Int32.Parse(TextBox3.Text.ToString()) - Total).ToString();
}
con1.Close();
I got the error from this line:
TextBox4.Text = (Int32.Parse(TextBox3.Text.ToString()) - Total).ToString();
It seems that I have an issue in subtracting those variables. Any help would be appreciated. Thanks!