简体   繁体   English

如何使用LIKE和%%运算符查询和过滤Web表单中的数据?

[英]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.

相关问题 如何在Web窗体中使用linq查询在网格视图中显示数据 - how to display the data in grid view using linq query in web form 如何使用Like SQL查询过滤数据表 - How filter datatable using Like same SQL query 除了使用像-或++这样的运算符外,如何更改变量? - How do you change a variable outside of using operators like — or ++? 如何在ASP.NET Web表单中为MS SQL编写具有多个过滤器输入的搜索查询 - How to write search query with multiple filter inputs in asp.net web form for ms sql 如何在Linq to NHibernate中使用按位运算符查询枚举标志 - How to query enum flags using bitwise operators in Linq to NHibernate 如何使用Web API上传文件和提交表单数据? - How to upload files and submit form data using Web API? 在字符串中使用%ad作为“赞”运算符来过滤查询结果 - Using %ad in a string for 'Like' operator to filter query results 使用Visual Studio查询构建器过滤数据 - Using Visual Studio query builder to filter data 使用Web表单将数据插入多个表 - inserting data into multiple tables using a web form 如何在我的Web Form应用程序中的任何地方访问来自Azure的用户数据? - How to access user data coming from Azure from everywhere in my Web Form App?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM