PDA

View Full Version : خلاصه کردن کد



programerinfonet
یک شنبه 12 آذر 1391, 16:06 عصر
چه طور میشه این کد رو کوتاه تر کرد

OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Crack\\Bankp.mdb");
con.Open();
OleDbCommand cs1 = new OleDbCommand("select Name from Table1 where sh_parvande=(" + t.Text + ")", con);
OleDbCommand cs2 = new OleDbCommand("select Family from Table1 where sh_parvande=(" + t.Text + ")", con);
OleDbCommand cs3 = new OleDbCommand("select FName from Table1 where sh_parvande=(" + t.Text + ")", con);
OleDbCommand cs4 = new OleDbCommand("select ShSh from Table1 where sh_parvande=(" + t.Text + ")", con);
OleDbCommand cs5 = new OleDbCommand("select MeliCode from Table1 where sh_parvande=(" + t.Text + ")", con);
OleDbCommand cs6 = new OleDbCommand("select Birthday from Table1 where sh_parvande=(" + t.Text + ")", con);
OleDbCommand cs7 = new OleDbCommand("select Study from Table1 where sh_parvande=(" + t.Text + ")", con);
OleDbCommand cs8 = new OleDbCommand("select Marry from Table1 where sh_parvande=(" + t.Text + ")", con);
OleDbCommand cs9 = new OleDbCommand("select tel_ham from Table1 where sh_parvande=(" + t.Text + ")", con);


t1.Text = cs1.ExecuteScalar().ToString();
t2.Text = cs2.ExecuteScalar().ToString();
t3.Text = cs3.ExecuteScalar().ToString();
t4.Text = cs4.ExecuteScalar().ToString();
t5.Text = cs5.ExecuteScalar().ToString();
t6.Text = cs6.ExecuteScalar().ToString();
t7.Text = cs7.ExecuteScalar().ToString();
t8.Text = cs8.ExecuteScalar().ToString();
t9.Text = cs9.ExecuteScalar().ToString();

hakim22
یک شنبه 12 آذر 1391, 19:46 عصر
OleDbCommand("select * from Table1 where sh_parvande=(" + t.Text + ")"

بعد خروجی رو به یک DataRow یا بهتره DataTable بریزید

خوبه که کمی در مورد SQL هم مطالعه کنید