0

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;
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

3

Replace following line:

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

with

    cmnd.CommandText = "SELECT Pojam FROM dbo.RecnikFinal";  
  • It isnt possible cause there is a problem such as NullReferenceException was unhandled - Object reference not set to an instance of an object ! p.s. that was the first thing that I tried to do.pls help – user2850503 Nov 05 '13 at 12:40
  • and its pointed to this piece of code - namesCollection.Add(dReader["Pojam"].ToString()); – user2850503 Nov 05 '13 at 12:50
  • SOLVED - the trick is changing SQL statement from - "SELECT top(10) Pojam FROM dbo.RecnikFinal"; to - "SELECT distinct Pojam FROM dbo.RecnikFinal Order by Pojam asc"; – user2850503 Nov 05 '13 at 13:35