通过c#.net自动完成带有sql的文本框 [英] auto complete text box with sql like operator by c#.net

查看:70
本文介绍了通过c#.net自动完成带有sql的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在Windows应用程序中有自动完成文本框,其中填充了数据库中的列表。但输入它只是从第一个字符开始过滤。我应该如何提供在自动完成文本中间搜索LIKE运算符的选项。



当我的用户开始输入jas之间的所有列表jas也应该被过滤和显示。

提前谢谢



i写了但是这段代码不起作用

Hi I have auto complete text box in Windows application where in it is populating the list from database. But typing it is filtering only starting with first character. How should i able to provide option to search in middle of the auto complete text as a LIKE operator.

When my user start typing jas all the list in between matches of jas also should be filtered and displayed.
Thanks in advance

i was wrote that but this code did not work

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace auto_complete_textbox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
       AutoCompleteStringCollection ACSC = new AutoCompleteStringCollection();
       
        private void textBox1_TextChanged(object sender, EventArgs e)
        {


            try
            {

                SqlCommand sqm = new SqlCommand("SELECT Location FROM DBO.Incident WHERE Location LIKE '%@Location%' ", new SqlConnection("data source=.;database=A police control system;uid=sa;pwd=sql"));
                sqm.Connection.Open();
                sqm.Parameters.Add("@Location", SqlDbType.NVarChar).Value = textBox1.Text;
                SqlDataReader sdr = sqm.ExecuteReader();
                if (sdr.HasRows == true)
                {
                    while (sdr.Read())
                    {
                      
                         ACSC.Add(sdr["Location"].ToString());

                    }

                }
                sqm.Connection.Close();
                textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
                textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
                textBox1.AutoCompleteCustomSource = ACSC;

            }
            catch (Exception ex)
            {

              messagebox.show(ex.message);
            }
          
           
        }

推荐答案

请参阅此链接 - >



http://www.codeproject.com/Articles/251110/AutoComplete-TextBox-with-substing-search-similar
plese refere this link-->

http://www.codeproject.com/Articles/251110/AutoComplete-TextBox-with-substing-search-similar


这篇关于通过c#.net自动完成带有sql的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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