简体   繁体   中英

code optimisation asp.net c#

The below given code of is taking infinitely long time to load in a web browser, when i click Button2,my browser keeps on loading.... and does not display the output. what can i do in my below given code to improve processing speed.

protected void Button2_Click(object sender, EventArgs e)
    {
        String a = DropDownList1.SelectedItem.Value;
        String b = DropDownList3.SelectedItem.Value.PadLeft(3, '0');      
        String c = TextBox2.Text.PadLeft(5,'0').ToString();
        String d = TextBox3.Text.ToString();
        String digit = a+ b  + c + d;
        string sql = "select * from testcase.main where reg_no =?";
        string sql1 = "select jname, jcode from heardt inner join judge ON heardt.jud1 = jcode";

try
            {
                using (OdbcConnection myConn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=testcase;User=root;Password=root;Option=3;"))
                {  
                     using (OdbcCommand cmd = new OdbcCommand(sql, myConn)) 
                        {
                            myConn.Open();
                            cmd.Parameters.AddWithValue("?", digit);
                            using (OdbcDataReader MyReader = cmd.ExecuteReader())
                                 {
                                    //**
                                    while (MyReader.Read())
                                    {
                                        String f = MyReader["pet_name"].ToString();
                                       String g = MyReader["res_name"].ToString();

                                        Label9.Visible = true;
                                        Label9.Text = f;

                                        Label10.Visible = true;
                                        Label10.Text = "VS";

                                        Label11.Visible = true;
                                        Label11.Text = g;

                                     }
                                 }
                         }
                }
            }
            catch (Exception e1)
            {
                Response.Write(e1.ToString());
            }
//***********************
try
        {
            using (OdbcConnection myConn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=testcase;User=root;Password=root;Option=3;"))
            {
                using (OdbcCommand cmd1 = new OdbcCommand(sql1, myConn))
                {
                    myConn.Open();

                    using (OdbcDataReader MyReader1 = cmd1.ExecuteReader())
                    {
                        //**
                        while (MyReader1.Read())
                        {
                            String f = MyReader1["jname"].ToString();
                            DropDownList4.Items.Add(f);

                        }
                    }
                }
            }
        }
        catch (Exception ee1)
        {
            Response.Write(ee1.ToString());
        }
 }

Is there any other way to execute query without using join operation for the following query??

select jname, jcode from heardt inner join judge ON heardt.jud1 = jcode

1- See if this query select jname, jcode from heardt inner join judge ON heardt.jud1 = jcode taking how much time.

2-see if you can use other driver than ODBC for MySQL and i am assuming that you are working with MySQL Database

  1. Do you really need to grab all the columns from the first sql? ("select *...")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM