سلام.
به گونه ای کد بنویسید که از کدنویسی لذت ببرید. اینکه در یک متد هرچی دم دستمون میاد رو بنویسیم که چاره کار نمیشه.
شما کانکشن رو به command، بایند نکردید.
معمولا جستجو براساس فیلدهای محدودی مثل کلید جدول یا فیلدهای کاربردی صورت میگیره و کمتر از این همه فیلد استفاده میشه ولی شاید واقعا نیاز داشتید که این همه شرط رو AND کردید!!.
یا از این کد استفاده کنید :
public DataTable Search_Allmelk(string k,string t,string m,string me,string g,string gh,string e,string ej)
{
SqlDataAdapter da = new SqlDataAdapter("select [Codemelk],[Typemelk],[Karbari],[Metraj],[Tedadkhab],[Tedadtabaghat],[Gheymatkol],[Gheymatejareh],[Address],[Vazeiat],[Name],[Family] from mema where Karbari=@k AND Typemelk=@t AND (Metraj<@me) AND (Metraj>@m) AND (Gheymatkol<@gh) AND (Gheymatkol>@g) AND (Gheymatejareh<@ej) AND (Gheymatejareh>@e)",con);
DataTable dt = new DataTable();
da.SelectCommand.Parameters.AddWithValue("@k",k);
da.SelectCommand.Parameters.AddWithValue("@t",t);
da.SelectCommand.Parameters.AddWithValue("@m",m);
da.SelectCommand.Parameters.AddWithValue("@me",me) ;
da.SelectCommand.Parameters.AddWithValue("@g",g);
da.SelectCommand.Parameters.AddWithValue("@gh",gh) ;
da.SelectCommand.Parameters.AddWithValue("@e",e);
da.SelectCommand.Parameters.AddWithValue("@ej",ej) ;
da.Fill(dt);
return dt;
}
یا از این کد :
public DataTable Search_Allmelk(string k,string t,string m,string me,string g,string gh,string e,string ej)
{
SqlCommand cmd = new SqlCommand("select [Codemelk],[Typemelk],[Karbari],[Metraj],[Tedadkhab],[Tedadtabaghat],[Gheymatkol],[Gheymatejareh],[Address],[Vazeiat],[Name],[Family] from mema where Karbari=@k AND Typemelk=@t AND (Metraj<@me) AND (Metraj>@m) AND (Gheymatkol<@gh) AND (Gheymatkol>@g) AND (Gheymatejareh<@ej) AND (Gheymatejareh>@e)",con);
cmd.Parameters.AddWithValue("@k",k);
cmd.Parameters.AddWithValue("@t",t);
cmd.Parameters.AddWithValue("@m",m);
cmd.Parameters.AddWithValue("@me",me);
cmd.Parameters.AddWithValue("@g",g);
cmd.Parameters.AddWithValue("@gh",gh);
cmd.Parameters.AddWithValue("@e",e);
cmd.Parameters.AddWithValue("@ej",ej);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
اگر جوابی برگشت داده نشد، درون جدولتون چنین جوابی با این شروط وجود نداره. پس به این مورد خوب دقت کنید.
موفق باشید.