autocomplete from local database c#

243 Views Asked by At

Im kindda stuck here big time, I just cant find the way to resolve this.

My local db is VistaDB. My code works when it comes to top 10 results,but I need to collect everything from the "Pojam" column to show in the textbox and not just the top 10 results.

My code runs in the text_changed event handler

Please help. Thanks in advance

        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

There are 1 best solutions below

3
Jakub Szułakiewicz On

Replace following line:

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

with

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