مرجع تخصصی برنامه نویسان

بزرگترین انجمن برنامه نویسان فارسی زبان

علت کند شدن پروژه با استفاده از Inner join

شنبه, 16 آذر 1398 15:46

علت کند شدن پروژه با استفاده از Inner join

سلام خدمت استاد محترم آقای مدائنی  

استاد محترم من از  Inner join  برای ارتباط با سه تیبل  استفاده کردم  ولی مشکل اساسی پیش  اومده و اون اینکه وقتی از Inner join اسفتاده میکنم سرعت فورم میاد پاین 

SELECT patient_Reg.PID, patient_Reg.Namee, Doctor.Name, gender.Gender, Usertype1.Usertype 
FROM Doctor 
INNER JOIN  patient_Reg ON Doctor.Doctor_ID = patient_Reg.Doctor_ID 
INNER JOIN     gender ON patient_Reg.G_ID = gender.G_ID 
INNER JOIN   Usertype1 ON patient_Reg.Usertype1ID = Usertype1.Usertype1ID 
where patient_Reg.PID=4

یکشنبه, 17 آذر 1398 12:29

خب inner بالا ترین مرتبه زمانی رو داره

سعی کن join تو در تو بزنی و از left , right و ... استفاده کنی

شنبه, 23 آذر 1398 12:07

سلام ممنونم مشکل رو پیدا کردم  مشکل اصلی من از Query بود که در SelectedIndexChanged  گذاشته بودم ولی  وقتی کد های زیر رو قرار میدم خیلی کند میشه راهی وجود داره یا خیر 

string commandText1 = "select  SUM(isnull(opd,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt1 = new SqlCommand(commandText1, db.con);
            db.con.Open();
            lblopd.Text = dt1.ExecuteScalar().ToString();
            db.con.Close();

            string commandText2 = "select  SUM(isnull(lab,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt2 = new SqlCommand(commandText2, db.con);
            db.con.Open();
            lbllab.Text = dt2.ExecuteScalar().ToString();
            db.con.Close();

            string commandText3 = "select  SUM(isnull(endoc,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt3 = new SqlCommand(commandText3, db.con);
            db.con.Open();
            lblendos.Text = dt3.ExecuteScalar().ToString();
            db.con.Close();

            string commandText4 = "select  SUM(isnull(ultr,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt4 = new SqlCommand(commandText4, db.con);
            db.con.Open();
            lblultra.Text = dt4.ExecuteScalar().ToString();
            db.con.Close();

            string commandText5 = "select  SUM(isnull(dnc,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt5 = new SqlCommand(commandText5, db.con);
            db.con.Open();
            lbldnc.Text = dt5.ExecuteScalar().ToString();
            db.con.Close();

            string commandText6 = "select  SUM(isnull(gyn,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt6 = new SqlCommand(commandText6, db.con);
            db.con.Open();
            lblgyn.Text = dt6.ExecuteScalar().ToString();
            db.con.Close();

            string commandText7 = "select  SUM(isnull(dliver,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt7 = new SqlCommand(commandText7, db.con);
            db.con.Open();
            lbldeliver.Text = dt7.ExecuteScalar().ToString();
            db.con.Close();

            string commandText8 = "select  SUM(isnull(orth,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt8 = new SqlCommand(commandText8, db.con);
            db.con.Open();
            lblortho.Text = dt8.ExecuteScalar().ToString();
            db.con.Close();

            string commandText9 = "select  SUM(isnull(ambu,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt9 = new SqlCommand(commandText9, db.con);
            db.con.Open();
            lblambu.Text = dt9.ExecuteScalar().ToString();
            db.con.Close();

            string commandText10 = "select  SUM(isnull(echo,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt10 = new SqlCommand(commandText10, db.con);
            db.con.Open();
            lblecho.Text = dt10.ExecuteScalar().ToString();
            db.con.Close();

            string commandText11 = "select  SUM(isnull(xrdg,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt11 = new SqlCommand(commandText11, db.con);
            db.con.Open();
            lblxrydigi.Text = dt11.ExecuteScalar().ToString();
            db.con.Close();

            string commandText12 = "select  SUM(isnull(xrs,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt12 = new SqlCommand(commandText12, db.con);
            db.con.Open();
            lblxrys.Text = dt12.ExecuteScalar().ToString();
            db.con.Close();

            string commandText13 = "select  SUM(isnull(xrd,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt13 = new SqlCommand(commandText13, db.con);
            db.con.Open();
            lblxryd.Text = dt13.ExecuteScalar().ToString();
            db.con.Close();

            string commandText14 = "select  SUM(isnull(emg,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt14 = new SqlCommand(commandText14, db.con);
            db.con.Open();
            lblemerg.Text = dt14.ExecuteScalar().ToString();
            db.con.Close();

            string commandText15 = "select  SUM(isnull(ecg,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt15 = new SqlCommand(commandText15, db.con);
            db.con.Open();
            lblecg.Text = dt15.ExecuteScalar().ToString();
            db.con.Close();

            string commandText16 = "select  SUM(isnull(bed,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt16 = new SqlCommand(commandText16, db.con);
            db.con.Open();
            lblbed.Text = dt16.ExecuteScalar().ToString();
            db.con.Close();

            string commandText17 = "select  SUM(isnull(ot,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt17 = new SqlCommand(commandText17, db.con);
            db.con.Open();
            lblot.Text = dt17.ExecuteScalar().ToString();
            db.con.Close();

            string commandText18 = "select  SUM(isnull(pthrap,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt18 = new SqlCommand(commandText18, db.con);
            db.con.Open();
            lblptherap.Text = dt18.ExecuteScalar().ToString();
            db.con.Close();

            string commandText19 = "select  SUM(isnull(phar,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt19 = new SqlCommand(commandText19, db.con);
            db.con.Open();
            lblpharmacy.Text = dt19.ExecuteScalar().ToString();
            db.con.Close();

            string commandText20 = "select  SUM(isnull(dental,0)) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt20 = new SqlCommand(commandText20, db.con);
            db.con.Open();
            lbldental.Text = dt20.ExecuteScalar().ToString();
            db.con.Close();

            string commandText21 = "select  SUM(opd+lab+endoc+ultr+dnc+gyn+dliver+orth+ambu+echo+xrdg+xrs+xrd+emg+ecg+bed+ot+pthrap+phar+dental) as total from pfee where   PID = '" + lblpid.Text + "'";
            SqlCommand dt21 = new SqlCommand(commandText21, db.con);
            db.con.Open();
            lbltotal.Text = dt21.ExecuteScalar().ToString();
            db.con.Close();

ارسال پاسخ برای این تاپیک

ارسال پاسخ مخصوص اعضا سایت می باشد ! میتوانید با حساب کاربری خود وارد سایت شده یا ثبت نام کنید