基于单选列表SQL语句错误的列表框过滤 [英] Listbox filtering based on radiolist sql statement error

查看:68
本文介绍了基于单选列表SQL语句错误的列表框过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里遇到了一个大问题.我知道我的查询不完整,但是我不知道我要寻找的确切功能是什么.如您所见,IVE创建了一个单选按钮列表A-Z,我希望根据选择的单选列表值对我的列表框进行过滤.我的问题是,当我单击一个字母时,所有由所选字母a组成的数据都将显示在我的列表框中,我只希望发布数据的第一个字母.对不起,我的英语能力更强
请注意,过滤是我的广播列表的名称

got a huge problem here. I know that my query is not complete but i dont know what the exact function that i am looking for. As you see ive created a radiobuttonlist A-Z and i want my list box to be filtered according to what the selected value of my radiolist. My problem is that when I clicked a letter all the data composing of choosed letter a will be displayed on my list box where i just want the first letter of the data to be published. Sorry for my english and more power
note that filtering is the name of my radiolist

Public Sub listcoursecode()
        Do While strsql = String.Empty
            strsql = "select * from [tblCourseTitle] where CourseCode like '%" & Trim(filtering.SelectedValue) & "%' Order by [CourseCode]Asc"
            Dim cmd As SqlCommand = New SqlCommand(strsql, cn)
            cn.Open()
            lbCourseCode.DataSource = cmd.ExecuteReader
            lbCourseCode.DataTextField = "CourseCode"
            lbCourseCode.DataValueField = "CourseTitle"
            lbCourseCode.DataBind()
        Loop
        cn.Close()
        strsql = String.Empty
    End Sub

    Protected Sub filtering_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles filtering.SelectedIndexChanged
        listcoursecode()
    End Sub
End Class

推荐答案

like ''%" & Trim(filter
从查询中删除%符号.
%实际上选择了所有包含"a"的单词.如果将其删除,则将提取所有包含第一个字符的单词.
like ''%" & Trim(filter
Remove the % symbol from your query.
% actually selects all words containing ''a''. If you remove it, all words containing the first character will be picked up.


尝试使用此

try with this

strsql = "select * from [tblCourseTitle] where CourseCode like '" & Trim(filtering.SelectedValue) & "%' Order by [CourseCode]Asc"


如果要从A-Z的第一个字符开始获取数据,请从查询中仅删除前%


remove only first % from query if you want to get data start from first character from A-Z


这篇关于基于单选列表SQL语句错误的列表框过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆