从本地数据库自动完成c#

时间:2013-11-05 11:09:02

标签: c# vistadb

我很友好地被困在这里,我只是找不到解决这个问题的方法。

我的本​​地数据库是VistaDB。我的代码在前10个结果中有效,但我需要收集“Pojam”列中的所有内容以显示在文本框中,而不仅仅是前10个结果。

我的代码在text_changed事件处理程序

中运行

请帮忙。提前致谢

        string pojam = UppercaseFirst(TextBoxPojam.Text.ToLower());
        AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();
        VistaDBConnection con = new VistaDBConnection(@"data source='|DataDirectory|Recnik.vdb4';Pooling=true;Open Mode = NonexclusiveReadWrite;");
        con.Open();
        VistaDBCommand cmnd = con.CreateCommand();
        cmnd.CommandType = CommandType.Text;
        cmnd.CommandText = "SELECT top(10) Pojam FROM dbo.RecnikFinal";  
        VistaDBDataReader dReader;
        dReader = cmnd.ExecuteReader();

        if (dReader.Read())
        {
            while (dReader.Read())
                namesCollection.Add(dReader["Pojam"].ToString());
        }
        else
        {
            MessageBox.Show("Data not found");
        }
        dReader.Close();

        TextBoxPojam.AutoCompleteMode = AutoCompleteMode.Suggest;
        TextBoxPojam.AutoCompleteSource = AutoCompleteSource.CustomSource;
        TextBoxPojam.AutoCompleteCustomSource = namesCollection;

1 个答案:

答案 0 :(得分:3)

替换以下行:

    cmnd.CommandText = "SELECT top(10) Pojam FROM dbo.RecnikFinal";  

    cmnd.CommandText = "SELECT Pojam FROM dbo.RecnikFinal";