如何使用SQL函数加载组合框? [英] How to load combobox using SQL like function?

查看:63
本文介绍了如何使用SQL函数加载组合框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下命令找到我的数据

 

SELECT name FROM emp WHERE name LIKE'%ahmed%'

并得到结果:

 name 
========
Md.Momin
Sarkar
Ahmed

我使用的相同sql代码组合框和加载数据

 con.Open(); 
SqlCommand cmd = new SqlCommand(" SELECT name FROM emp WHERE name LIKE'" +'%'+ comboBox1.Text +'%'+"'",con);
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
comboBox1.Items.Add(dr [0] .ToString());

}
con.Close();


在组合框系统下不返回结果 
没有类似函数通常我可以使用代码
 我如何在组合框中使用搜索字符串? ?




解决方案

Khan先生,


第一次你的组合框是空的,所以你正在处理众所周知的"首先是鸡肉或鸡蛋"。问题 


I can find my data using the following command

SELECT name FROM emp WHERE name LIKE '%ahmed%'

and get result :

name
======== 
Md.Momin 
Sarkar 
Ahmed

same sql code I have use combobox and load data

con.Open();
SqlCommand cmd = new SqlCommand("SELECT name FROM emp WHERE name LIKE '" + '%' + comboBox1.Text + '%' + "'", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr[0].ToString());

}
con.Close();

under the combobox system do not return result but without like function normally i can load data using the code How can i have search string in combobox??


解决方案

Mr Khan,

The first time your combobox is empty, so you are dealing with the well known "Which was first the Chicken or the Egg" problem 


这篇关于如何使用SQL函数加载组合框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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