帮助:修改了我的搜索按钮编码 [英] Help: modified my coding for search button

查看:81
本文介绍了帮助:修改了我的搜索按钮编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai,我想修改我的代码,在此附上我的示例代码.此代码用于在与数据库sql 2005连接的Microsoft Visual 2005中使用的搜索按钮.在此代码中,我使用一个按钮在数据库sql中进行搜索2005,我将其重命名为按钮搜索,并且如果按钮找到了我要搜索的答案,则使用一个文本框来显示答案.如果我在文本框中输入要查找的名称,然后单击按钮搜索,则答案将以staff.形式出现.问题是,如果我在数据库中找不到该名称的文本框中输入新名称,则没有消息找不到用于显示名称的框.因此,在这里我需要您的建议,如果& else语句可解决此问题.例如,如果名称不可用,则消息框将显示警告未找到数据".这是代码

hai ,i want modify my code,here i attach my example code .This code is for search button which i use in microsoft visual 2005 connected with database sql 2005.In this code i use one button use to search in database sql 2005 which i rename it button search and one textbox use to display answer if the button found the answer that i want to search. If i write the name which i want to find in text box then i click button search then the answer will appear in form of staff.Probleam is ,if i write new name in the textbox which that name not available in database , then no message box to display name is not found.So here i need your advice how i can use if & else statement to solve this problem. For example if the name is not available that the messagebox will show warning the "no found data"..here is the code

Private Sub Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearch.Click
        Me.StaffBindingSource.Filter = "Name LIKE' " & Me.txtsearch.Text & "'%"
End Sub


为您使用的信息按钮名称,我使用的是btnsearch和文本框,我使用的是txtsearch
我的数据库名称是login,表名称是staff.该表中有用于输入姓名,电话,地址和密码的列...请提供帮助,我如何理解您给出的解释.
由losmac(代码块)编辑[/EDIT]


hai感谢您的回复..我按照您的解决方案进行操作,但由于我遇到错误而无法正常运行
错误``行''不是``System.Windows.Forms.BindingSource''的成员.

这是由您的指南修改的我的代码

私有子Search_Click(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理btnsearch.Click
如果Me.StaffBindingSource.Filter ="Name LIKE"& Me.txtsearch.Text& %""
和我. StaffBindingSource.Rows.Count = 0 然后
MsgBox(找不到数据")
如果结束
结束Sub


for your info button name i use is btnsearch and textbox i use is txtsearch
my database name is login, table name is staff. in this table there is column for name, telephone, address and password...please help please, i how your understand explaination i given.
Edited by losmac (code block)[/EDIT]


hai thanks for reply.. i follow your solution but it not work because i got an error
Error''Rows'' is not a member of ''System.Windows.Forms.BindingSource''.

Here is my code which i modified by your guide

Private Sub Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearch.Click
If Me.StaffBindingSource.Filter = "Name LIKE ''" & Me.txtsearch.Text & "%''"
And Me.StaffBindingSource.Rows.Count = 0 Then
MsgBox("Data Not found")
End If
End Sub

推荐答案

第一:
Me.StaffBindingSource.Filter = "Name LIKE' " & Me.txtsearch.Text & "'%"



应该变成:



should become:

Me.StaffBindingSource.Filter = "Name LIKE '" & Me.txtsearch.Text & "%'"





如果Me.StaffBindingSource.Rows.Count = 0,则显示消息未找到"



and

if Me.StaffBindingSource.Rows.Count = 0 then show your message ''Not found''


这篇关于帮助:修改了我的搜索按钮编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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