Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a textbox_textchange on a web form and It is not working any more. I was testing the code and everything was working but now it doesn't.

When a user logs in and goes to a form the user can enter a number into the textbox and the users data from a previous year populates the textboxes on the form. Then the user can enter new data into the other textboxes and submit it to the database. The only thing that is not working is the numbers that the user enters into the textbox for the text change to show the previous year. Plus the numbers entered into the textbox must match the users ID number. If not the user can enter any number and it will show any users previous year data. How can I fix this?

C#
protected void TextBoxUNITID_TextChanged(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
            con.Open();

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

            SqlCommand scmd = new SqlCommand("Select INST_ID, UNITID, ASTUDENTS, ACOMPLETED, ATRANSFERS, BSTUDENTS, BCOMPLETED, BTRANSFERS, YEAR from Table442012 where UNITID = @TextBoxUNITID", con);
            SqlCommand scmd2 = new SqlCommand("Select INST_ID, UNITID, ASTUDENTS, ACOMPLETED, ATRANSFERS, BSTUDENTS, BCOMPLETED, BTRANSFERS, YEAR from Table442012 where INST_ID = @TextBoxINST_ID", con);
            SqlCommand scmd3 = new SqlCommand("Select INST_ID, UNITID, ASTUDENTS, ACOMPLETED, ATRANSFERS, BSTUDENTS, BCOMPLETED, BTRANSFERS, YEAR from Table452013 where UNITID = @TextBoxUNITID", con2);
            SqlCommand scmd4 = new SqlCommand("Select INST_ID, UNITID, ASTUDENTS, ACOMPLETED, ATRANSFERS, BSTUDENTS, BCOMPLETED, BTRANSFERS, YEAR from Table452013 where INST_ID = @TextBoxINST_ID", con2);
            scmd.Parameters.Add(new SqlParameter("@TextBoxUNITID", TextBoxUNITID.Text));
            scmd2.Parameters.Add(new SqlParameter("@TextBoxINST_ID", TextBoxINST_ID.Text));
            scmd3.Parameters.Add(new SqlParameter("@TextBoxUNITID", TextBoxUNITID.Text));
            scmd4.Parameters.Add(new SqlParameter("@TextBoxINST_ID", TextBoxINST_ID.Text));
            SqlDataReader dr = scmd.ExecuteReader();
            SqlDataReader dr2 = scmd3.ExecuteReader();

            if (dr.Read())
                if (dr2.Read())
            {
                TextBoxLYTNUGSC.Text = dr["ASTUDENTS"].ToString();
                TextBoxLYTNUGSCD.Text = dr["ACOMPLETED"].ToString();
                TextBoxLYTTOUG.Text = dr["ATRANSFERS"].ToString();
                TextBoxLYTNGSC.Text = dr["BSTUDENTS"].ToString();
                TextBoxLYTNGSCD.Text = dr["BCOMPLETED"].ToString();
                TextBoxLYTTOG.Text = dr["BTRANSFERS"].ToString();
                TextBoxINST_ID.Text = dr["INST_ID"].ToString();
                TextBoxLYEAR.Text = dr["YEAR"].ToString();

                TextBoxTNUGSC.Text = dr2["ASTUDENTS"].ToString();
                TextBoxTNUGSCD.Text = dr2["ACOMPLETED"].ToString();
                TextBoxTTOUG.Text = dr2["ATRANSFERS"].ToString();
                TextBoxTNGSC.Text = dr2["BSTUDENTS"].ToString();
                TextBoxTNGSCD.Text = dr2["BCOMPLETED"].ToString();
                TextBoxTTOG.Text = dr2["BTRANSFERS"].ToString();
                TextBoxINST_ID.Text = dr2["INST_ID"].ToString();
                TextBoxLYEAR.Text = dr2["YEAR"].ToString();
                TextBoxTNUGSC.Focus();
            }
            dr.Close();
            dr2.Close();
            con.Close();
            con2.Close();
        }
Posted

1 solution

I solved the issue!!!! Here is my updated code:

C#
protected void TextBoxUNITID_TextChanged(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
            con.Open();

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

            if (true)
            {
                SqlCommand level = new SqlCommand("select UNITID ,INST_ID from Table442012 where UNITID = @UNITID AND INST_ID = @INST_ID", con);
                level.Parameters.Add(new SqlParameter("UNITID", TextBoxUNITID.Text));
                level.Parameters.Add(new SqlParameter("INST_ID", TextBoxINST_ID.Text));

                SqlCommand scmd = new SqlCommand("Select INST_ID, UNITID, ASTUDENTS, ACOMPLETED, ATRANSFERS, BSTUDENTS, BCOMPLETED, BTRANSFERS, YEAR from Table442012 where UNITID = @TextBoxUNITID", con);
                SqlCommand scmd2 = new SqlCommand("Select INST_ID, UNITID, ASTUDENTS, ACOMPLETED, ATRANSFERS, BSTUDENTS, BCOMPLETED, BTRANSFERS, YEAR from Table452013 where UNITID = @TextBoxUNITID", con2);
                scmd.Parameters.Add(new SqlParameter("@TextBoxUNITID", TextBoxUNITID.Text));
                scmd2.Parameters.Add(new SqlParameter("@TextBoxUNITID", TextBoxUNITID.Text));
                SqlDataReader dr = scmd.ExecuteReader();
                SqlDataReader dr2 = scmd2.ExecuteReader();

                if (dr.Read())
                    if (dr2.Read())
                {
                    TextBoxLYTNUGSC.Text = dr["ASTUDENTS"].ToString();
                    TextBoxLYTNUGSCD.Text = dr["ACOMPLETED"].ToString();
                    TextBoxLYTTOUG.Text = dr["ATRANSFERS"].ToString();
                    TextBoxLYTNGSC.Text = dr["BSTUDENTS"].ToString();
                    TextBoxLYTNGSCD.Text = dr["BCOMPLETED"].ToString();
                    TextBoxLYTTOG.Text = dr["BTRANSFERS"].ToString();
                    TextBoxINST_ID.Text = dr["INST_ID"].ToString();
                    TextBoxLYEAR.Text = dr["YEAR"].ToString();

                    TextBoxTNUGSC.Text = dr2["ASTUDENTS"].ToString();
                    TextBoxTNUGSCD.Text = dr2["ACOMPLETED"].ToString();
                    TextBoxTTOUG.Text = dr2["ATRANSFERS"].ToString();
                    TextBoxTNGSC.Text = dr2["BSTUDENTS"].ToString();
                    TextBoxTNGSCD.Text = dr2["BCOMPLETED"].ToString();
                    TextBoxTTOG.Text = dr2["BTRANSFERS"].ToString();
                    TextBoxINST_ID.Text = dr2["INST_ID"].ToString();
                    TextBoxYEAR.Text = dr2["YEAR"].ToString();
                    TextBoxTNUGSC.Focus();
                }

                dr.Close();
                con.Close();
                dr2.Close();
                con2.Close();
            }
        }
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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