Click here to Skip to main content
15,914,327 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a form that shows a users data from last year in a set of text boxes. I want to show the data that the user just entered into the database after they have clicked on submit. I have it working so far for the users that have data in those fields but for the users that doesn't have data in the database for this year the form looks weird and doesn't display certain things. How can I correct this issue and display the data that the new users has entered?



C#
protected void Page_Load(object sender, EventArgs e)
    {
        ButtonPrint.Attributes.Add("onclick", "window.print(); return false");

        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con2.Open();
        SqlConnection con3 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con3.Open();

        TextBoxINST_ID.Text = Session["inst_id"].ToString();
        SqlCommand scmd = new SqlCommand("Select INST_ID, LongName, City, State from TableCOCINST where INST_ID = '" + TextBoxINST_ID.Text + "'", con);
        SqlCommand scmd2 = new SqlCommand("Select INST_ID, INSTRUCTIO, RESEARCH, PUBLIC_SER, ACADEMIC_S, STUDENT_SE, INSTITUTIO, PHYSICAL_P, SCHOLARSHI, AUXILIARY_, HOSPITALS, INDEPENDEN, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT from TableFIN2012 where INST_ID = '" + TextBoxINST_ID.Text + "'", con2);
        SqlCommand scmd3 = new SqlCommand("Select INST_ID, TOTAL_REVE, INSTRUCTIO, RESEARCH, PUBLIC_SER, ACADEMIC_S, STUDENT_SE, INSTITUTIO, PHYSICAL_P, SCHOLARSHI, AUXILIARY_, HOSPITALS, INDEPENDEN, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, EXPENDABLE, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT from TableFIN2013 where INST_ID = '" + TextBoxINST_ID.Text + "'", con3);
        SqlDataReader dr = scmd.ExecuteReader();
        SqlDataReader dr2 = scmd2.ExecuteReader();
        SqlDataReader dr3 = scmd3.ExecuteReader();

Code for showing last year data:

        if (dr.Read())
        if (dr2.Read())
        if (dr3.Read())
            {
                lblCity.Text = dr["City"].ToString();
                lblState.Text = dr["State"].ToString();
                lblSchool.Text = dr["LongName"].ToString();
                lblSchool2.Text = dr["LongName"].ToString();
                TextBoxLYInstr.Text = dr2["INSTRUCTIO"].ToString();
                TextBoxLYRes.Text = dr2["RESEARCH"].ToString();
                TextBoxLYPubS.Text = dr2["PUBLIC_SER"].ToString();
                TextBoxLYAcad.Text = dr2["ACADEMIC_S"].ToString();
                TextBoxLYStudS.Text = dr2["STUDENT_SE"].ToString();
                TextBoxLYInstiS.Text = dr2["INSTITUTIO"].ToString();
                TextBoxLYOperM.Text = dr2["PHYSICAL_P"].ToString();
                TextBoxLYSFEDA.Text = dr2["SCHOLARSHI"].ToString();
                TextBoxLYAuxE.Text = dr2["AUXILIARY_"].ToString();
                TextBoxLYHosS.Text = dr2["HOSPITALS"].ToString();
                TextBoxLYIndeO.Text = dr2["INDEPENDEN"].ToString();
                TextBoxLYOED.Text = dr2["OTHEREXP"].ToString();
                TextBoxLYTA.Text = dr2["TOTASSETS"].ToString();
                TextBoxLYTL.Text = dr2["TOTLIABILITY"].ToString();
                TextBoxLYNPRNA.Text = dr2["NoNEXPPERMRESASSETS"].ToString();
                TextBoxLYTUNA.Text = dr2["UNRNETASSETS"].ToString();
                TextBoxLYTR.Text = dr2["TOTALREV"].ToString();
                TextBoxLYTFN.Text = dr2["TUITFEES"].ToString();
                TextBoxLYCD.Text = dr2["CURRDEBT"].ToString();
                TextBoxLYLTD.Text = dr2["LONGTERMDEBT"].ToString();

Code for showing this year data:

                TextBoxTROA.Text = dr3["TOTAL_REVE"].ToString();
                TextBoxInstr.Text = dr3["INSTRUCTIO"].ToString();
                TextBoxRes.Text = dr3["RESEARCH"].ToString();
                TextBoxPubS.Text = dr3["PUBLIC_SER"].ToString();
                TextBoxAcad.Text = dr3["ACADEMIC_S"].ToString();
                TextBoxStudS.Text = dr3["STUDENT_SE"].ToString();
                TextBoxInstiS.Text = dr3["INSTITUTIO"].ToString();
                TextBoxOperM.Text = dr3["PHYSICAL_P"].ToString();
                TextBoxSFEDA.Text = dr3["SCHOLARSHI"].ToString();
                TextBoxAuxE.Text = dr3["AUXILIARY_"].ToString();
                TextBoxHosS.Text = dr3["HOSPITALS"].ToString();
                TextBoxIndeO.Text = dr3["INDEPENDEN"].ToString();
                TextBoxOED.Text = dr3["OTHEREXP"].ToString();
                TextBoxTA.Text = dr3["TOTASSETS"].ToString();
                TextBoxTL.Text = dr3["TOTLIABILITY"].ToString();
                TextBoxNPRNA.Text = dr3["NoNEXPPERMRESASSETS"].ToString();
                TextBoxETRNA.Text = dr3["EXPENDABLE"].ToString();
                TextBoxTUNA.Text = dr3["UNRNETASSETS"].ToString();
                TextBoxTR.Text = dr3["TOTALREV"].ToString();
                TextBoxTFN.Text = dr3["TUITFEES"].ToString();
                TextBoxCD.Text = dr3["CURRDEBT"].ToString();
                TextBoxLTD.Text = dr3["LONGTERMDEBT"].ToString();

                

            }
        dr.Close();
        con.Close();
        dr2.Close();
        con2.Close();
        dr3.Close();
        con3.Close();

    }
Posted

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