首页 > 解决方案 > 如何从数据库中获取最近添加的值到自动完成文本框

问题描述

如何将最近添加的值从我的数据库中获取到我的文本框(使用 Autosuggest) 我需要退出应用程序才能查看最近添加到我的文本框的值。我希望有人能在这件事上帮助我。

 public void AutoSuggest()
    {
        List<string> col = new List<string>();
        using (var con = SQLConnection.GetConnection())
        {
            using (var select = new SqlCommand("Select Codeitem from employee_product", con))
            {

                using (var reader = select.ExecuteReader())
                {

                    while (reader.Read())
                    {
                        col.Add(reader["Codeitem"].ToString());
                    }                        
                    txt_code.AutoCompleteMode           = AutoCompleteMode.SuggestAppend;
                    txt_code.AutoCompleteSource         = AutoCompleteSource.CustomSource;
                    txt_code.AutoCompleteCustomSource.Clear();
                    txt_code.AutoCompleteCustomSource.AddRange(col.ToArray());
                    AddingProduct();
                }
            }
        }
    }

在此处输入图像描述 此图片用于添加我的产品,您可以看到最近添加的产品是选定的。

在此处输入图像描述 此图像用于获取我的产品的代码值。您可以看到当我尝试输入代码时,他无法建议最近添加的

标签: c#sql-servervisual-studiowinforms

解决方案


推荐阅读