abyar_fm
شنبه 25 شهریور 1391, 19:42 عصر
سلام دوستان J
من چهارتا فیلد درفرمم دارم که میخوام جستجوی پیشرفته(ترکیبی با چهار فیلد) رو با استفاده از دستور likeدر linq انجام بدم.بلوک کدی که در روش ADO داشتم این بود
string sql;
sql = " SELECT id_bimar ,name ,family , name_pedar, code_melli,tarikhe_tavalod ,name_bime ,
shomare_daftarche" +
" , tarikh_paziresh,bimary_khas,telephon ,adress" +
" FROM vw_paziresh where ";
if (txt_codeparvande.Text != string.Empty)
sql = sql + "id_bimar like N'" + txt_codeparvande.Text + "%' and ";
if (txt_name.Text != string.Empty)
sql = sql + "name like N'" + txt_name.Text.Trim() + "' and ";
if (txt_family.Text != string.Empty)
sql = sql + "family like N'" + txt_family.Text.Trim() + "%' and ";
if (txt_telephne.Text != string.Empty)
sql = sql + "telephon like N'" + txt_telephne.Text + "%' and ";
sql = sql + " 1=1 ";
con = new SqlConnection(constring());
com = new SqlCommand(sql, con);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
da = new SqlDataAdapter(sql, con);
ds = new DataSet();
da.Fill(ds, "bimar");
dataGridView1.DataBindings.Clear();
dataGridView1.DataBindings.Add(new Binding("DataSource", ds, "bimar"));
con.Close();
حالا میخوام این دستور با متد StartWith() بنویسم نمیدونم باید چطور از این متد استفاده کنم.هرطور مینویسم error میده
من چهارتا فیلد درفرمم دارم که میخوام جستجوی پیشرفته(ترکیبی با چهار فیلد) رو با استفاده از دستور likeدر linq انجام بدم.بلوک کدی که در روش ADO داشتم این بود
string sql;
sql = " SELECT id_bimar ,name ,family , name_pedar, code_melli,tarikhe_tavalod ,name_bime ,
shomare_daftarche" +
" , tarikh_paziresh,bimary_khas,telephon ,adress" +
" FROM vw_paziresh where ";
if (txt_codeparvande.Text != string.Empty)
sql = sql + "id_bimar like N'" + txt_codeparvande.Text + "%' and ";
if (txt_name.Text != string.Empty)
sql = sql + "name like N'" + txt_name.Text.Trim() + "' and ";
if (txt_family.Text != string.Empty)
sql = sql + "family like N'" + txt_family.Text.Trim() + "%' and ";
if (txt_telephne.Text != string.Empty)
sql = sql + "telephon like N'" + txt_telephne.Text + "%' and ";
sql = sql + " 1=1 ";
con = new SqlConnection(constring());
com = new SqlCommand(sql, con);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
da = new SqlDataAdapter(sql, con);
ds = new DataSet();
da.Fill(ds, "bimar");
dataGridView1.DataBindings.Clear();
dataGridView1.DataBindings.Add(new Binding("DataSource", ds, "bimar"));
con.Close();
حالا میخوام این دستور با متد StartWith() بنویسم نمیدونم باید چطور از این متد استفاده کنم.هرطور مینویسم error میده