I have a code in place to populate a form. The code will populate one set of textboxes and I have another code to populate the other set of textboxes. When the page loads I get an error, "Input string was not in a correct format". I know that the issue is the database that has Table2013 because it has no data in it. I want to populate the second set of textboxes with the data the user just entered into the database when the user comes back to the form to see what was entered. How can this be done?
protected void Page_Load(object sender, EventArgs e)
{
ButtonPrint.Attributes.Add("onclick", "window.print(); return false");
this.lblYEAR.Text = DateTime.Today.ToString("yyyy");
this.TextBoxDATE.Text = DateTime.Today.ToString("dd-MMM-yy");
this.lblTime.Text = System.DateTime.Now.ToShortTimeString();
TextBoxFTUG.Focus();
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con.Open();
SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con2.Open();
SqlConnection con3 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con3.Open();
TextBoxINST_ID.Text = Session["inst_id"].ToString();
SqlCommand scmd = new SqlCommand("Select INST_ID, LongName, City, State from TableCo where INST_ID = '" + TextBoxINST_ID.Text + "'", con);
SqlCommand scmd2 = new SqlCommand("Select INST_ID, FT_UNDERGR, FT_GRAD, FTE_UNDERG, FTE_GRAD, NON_CREDIT, TOTAL_FTE, FCFTUHC, FCFTPBHC, FCPTUHC, FCPTPBHC, NCHC, FTEYR from Table2012 where INST_ID = '" + TextBoxINST_ID.Text + "'", con2);
SqlCommand scmd3 = new SqlCommand("Select INST_ID, FT_UNDERGR, FT_GRAD, FTE_UNDERG, FTE_GRAD, NON_CREDIT, TOTAL_FTE, FCFTUHC, FCFTPBHC, FCPTUHC, FCPTPBHC, NCHC from Table2013 where INST_ID = '" + TextBoxINST_ID.Text + "'", con3);
SqlDataReader dr = scmd.ExecuteReader();
SqlDataReader dr2 = scmd2.ExecuteReader();
SqlDataReader dr3 = scmd3.ExecuteReader();
if (dr.Read())
if (dr2.Read())
if (dr3.Read())
{
lblCity.Text = dr["City"].ToString();
lblState.Text = dr["State"].ToString();
lblSchool.Text = dr["LongName"].ToString();
lblLYear.Text = dr2["FTEYR"].ToString();
TextBoxLYFTUG.Text = dr2["FT_UNDERGR"].ToString();
TextBoxLYFTG.Text = dr2["FT_GRAD"].ToString();
TextBoxLYTHUGDR.Text = dr2["FTE_UNDERG"].ToString();
TextBoxLYTHGDR.Text = dr2["FTE_GRAD"].ToString();
TextBoxLYNCCDR.Text = dr2["NON_CREDIT"].ToString();
TextBoxLYTCNC.Text = dr2["TOTAL_FTE"].ToString();
TextBoxLYTNFUG.Text = dr2["FCFTUHC"].ToString();
TextBoxLYTNFG.Text = dr2["FCFTPBHC"].ToString();
TextBoxLYTNCPUG.Text = dr2["FCPTUHC"].ToString();
TextBoxLYTNCPG.Text = dr2["FCPTPBHC"].ToString();
TextBoxLYTNNCC.Text = dr2["NCHC"].ToString();
TextBoxFTUG.Text = dr3["FT_UNDERGR"].ToString();
TextBoxFTG.Text = dr3["FT_GRAD"].ToString();
TextBoxTHUGDR.Text = dr3["FTE_UNDERG"].ToString();
TextBoxTHGDR.Text = dr3["FTE_GRAD"].ToString();
TextBoxNCCDR.Text = dr3["NON_CREDIT"].ToString();
TextBoxTCNC.Text = dr3["TOTAL_FTE"].ToString();
TextBoxTNFUG.Text = dr3["FCFTUHC"].ToString();
TextBoxTNFG.Text = dr3["FCFTPBHC"].ToString();
TextBoxTNCPUG.Text = dr3["FCPTUHC"].ToString();
TextBoxTNCPG.Text = dr3["FCPTPBHC"].ToString();
TextBoxTNNCC.Text = dr3["NCHC"].ToString();
}
dr.Close();
con.Close();
con2.Close();
dr2.Close();
con3.Close();
dr3.Close();
RangeValidatorLYTNFUG.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNFUG.Text) - Convert.ToInt32(TextBoxLYTNFUG.Text) * 20 / 100);
RangeValidatorLYTNFUG.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNFUG.Text) + Convert.ToInt32(TextBoxLYTNFUG.Text) * 20 / 100);
RangeValidatorLYTNFG.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNFG.Text) - Convert.ToInt32(TextBoxLYTNFG.Text) * 20 / 100);
RangeValidatorLYTNFG.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNFG.Text) + Convert.ToInt32(TextBoxLYTNFG.Text) * 20 / 100);
RangeValidatorLYTNCPUG.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNCPUG.Text) - Convert.ToInt32(TextBoxLYTNCPUG.Text) * 20 / 100);
RangeValidatorLYTNCPUG.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNCPUG.Text) + Convert.ToInt32(TextBoxLYTNCPUG.Text) * 20 / 100);
RangeValidatorLYTNCPG.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNCPG.Text) - Convert.ToInt32(TextBoxLYTNCPG.Text) * 20 / 100);
RangeValidatorLYTNCPG.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNCPG.Text) + Convert.ToInt32(TextBoxLYTNCPG.Text) * 20 / 100);
RangeValidatorLYTNNCC.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNNCC.Text) - Convert.ToInt32(TextBoxLYTNNCC.Text) * 20 / 100);
RangeValidatorLYTNNCC.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNNCC.Text) + Convert.ToInt32(TextBoxLYTNNCC.Text) * 20 / 100);
}