Click here to Skip to main content
15,945,603 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
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?

C#
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);

    }
Posted
Updated 2-Dec-13 10:00am
v2

1 solution

It is not that tough of a problem..Have a look at http://msdn.microsoft.com/en-us/library/75x4ha6s(v=vs.100).aspx[^]
As far as you error message is concerned , it seems to be coming from trying to convert text to integer when there is nothing there.. try it like this..
C#
int result=0;
if(int.TryParse(textBoxid.Text,out result))
 
Share this answer
 
Comments
Computer Wiz99 2-Dec-13 22:05pm    
learner's bug, Where should I put the code you showed?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900