如何通过提供部分名称显示员工的所有姓名? [英] How Do I Display All Names Of Employees By Providing Partial Name?

查看:65
本文介绍了如何通过提供部分名称显示员工的所有姓名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我给整个姓名搜索功能做得很好。问题是当我给出部分姓名时,它总是显示没有记录。任何人都可以帮助我。这真的很紧急。我的编码是在C#(winforms)

when i give whole of fellow name search function is doing well.The problem is when i give partial fellow name it is always displaying "no record". Can anyone please help me out.This is really urgent.My coding is in C#(winforms)

推荐答案

你提供的代码很容易注入SQL。始终使用Parameters.Add()将参数/动态值添加到SqlCommand对象。但是,我认为你的助手( MySqlHelper )不支持这一点。如果您希望您的代码更安全,您可以更改您的帮助。



回到您面临的问题:

你是不在搜索查询中使用通配符(%)。将SQLCommand查询替换为下面给出的查询:



The code you provided is prone to SQL injection. Always use Parameters.Add() to add parameters/dynamic values to your SqlCommand object. However, I think you helper(MySqlHelper) does not support that. You can change your helper if you want your code to be more secure.

Coming back to the problem you are facing:
You are not using wild card characters(%) in your search query. Replace the SQLCommand query with the one given below:

DataTable dtSearch = VMR.MySqlHelper.GetDataTable("select * from table_name where S_ID = '" + txtSearch.Text + "' OR Fellow_name like '%" + txtSearch1.Text + "%'");


这篇关于如何通过提供部分名称显示员工的所有姓名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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