[英]How to query and filter my data in web form by using LIKE and %% operators?
I want to filter and select data from sql server in my web form by using LIKE and % % operator 我想通过使用LIKE和%%运算符从我的Web表单中的sql server中筛选和选择数据
I searched in stackoverflow solutions but i cannot find the solution to my case and i tried alot but its not working correctly. 我在stackoverflow解决方案中进行了搜索,但找不到适合我的情况的解决方案,我尝试了很多,但无法正常工作。 This is my code:
这是我的代码:
protected void BtnSearch_Click(object sender, EventArgs e)
{
string sql = @" SELECT [appt_id],visitor_name,mobile ,work_place.work_place_name as work_place_name,days.day as day,date,[time],[subject],[duration],appointment_place.appt_place as appt_place
FROM [Appointments]
inner join days on days.day_id = Appointments.day_id
inner join appointment_place on appointment_place.appt_place_id =Appointments.appt_place_id
inner join work_place on work_place.work_place_id = Appointments.work_place_id
where 1=1 ";
string condition = "";
string orderby = "order by date";
// orderby += "order by appointments.time";
if (txtVisitorName.Text != "")
{
condition += " and appointments.visitor_name like '" + txtVisitorName.Text + "'";
}
if (txtsubject.Text != "")
{
condition += " and appointments.subject like '" + txtsubject.Text + "'";
}
if (txtMobileNo.Text != "")
{
condition += " and appointments.mobile ='" + txtMobileNo.Text + "'";
}
DataTable dt = func.fireDatatable(string.Format(sql + condition + orderby));
gvappt.DataSource = dt;
gvappt.DataBind();
}
I expect the output of code to use LIKE and %% to search visitors name or subject contains part of name or part of subject ? 我希望代码的输出使用LIKE和%%来搜索访问者的姓名或主题,其中包含名称的一部分还是主题的一部分?
I found the correct answer to my question : 我找到了我问题的正确答案:
if (txtDocSubject.Text != "")
{
condition +=" and Documents.Document_subject like '%"+txtDocSubject.Text+"%'";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.