Need Help with Auto-Complete; textBox1 Mapped to and SQL Server DB


  • Dear C# experts!  I am trying to run the auto-complete code from here:



    I modified it a bit to work with my SLQ Server DB.  Here’s what I have now:

    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;

    using System.Configuration;

    using System.Collections.Specialized;



    namespace WindowsFormsApplication3


        publicpartialclassForm1: Form



            //public string strConnection = ConfigurationManager.AppSettings["ConnString"];

            //AutoCompleteStringCollection namesCollection =

            //new AutoCompleteStringCollection();








                    publicpartialclassfrmAuto: Form


                publicstringstrConnection =


                AutoCompleteStringCollectionnamesCollection =



                privatevoidForm1_Load(objectsender, EventArgse)



                    SqlConnectionconn = newSqlConnection("Server='Excel-PC';Database='Northwind';Trusted_Connection=True");

                    conn.ConnectionString = strConnection;

                    SqlCommandcmd = newSqlCommand();

                    cmd.Connection = conn;

                    cmd.CommandType = CommandType.Text;

                    cmd.CommandText =

                    "Select distinct [CompanyName] from [Customers]"+

                    " order by [CompanyName] asc";


                    dReader = cmd.ExecuteReader();

                    if(dReader.HasRows == true)







                        MessageBox.Show("Data not found");




                    textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;

                    textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;

                    textBox1.AutoCompleteCustomSource = namesCollection;



                privatevoidbtnCancel_Click(objectsender, EventArgse)




                privatevoidbtnOk_Click(objectsender, EventArgse)


                    MessageBox.Show("Hope you like this example");










    I’m getting the following errors (which don’t make sense to me):

    Error    1          The name 'ConfigurationManager' does not exist in the current context


    I have this:

    using System.Configuration;


    Though it would take care of the error, but nope.


    Also, 3 red squiggle lines under textBox1:

    Error    2          Cannot access a non-static member of outer type 'WindowsFormsApplication3.Form1' via nested type 'WindowsFormsApplication3.Form1.frmAuto'


    I have a ‘textBox1’ and the case sensitivity matches, so I’m not sure what’s causing this error.


    Can someone please help me get this working?


    Thanks everyone!!




    Montag, 5. März 2012 04:50


Alle Antworten

  • Does anyone know how to do this???  I know a little C#, but obviously not as much as I thought!!
    Dienstag, 6. März 2012 04:13
  • I figure it out!!  Solution here!!


    Hope that helps others!!

    Dienstag, 6. März 2012 04:58
  • Hi ryguy72,

    I'm glad to hear that you got it working. If you have any difficulty in future programming, we welcome you to post here again.

    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

    Mittwoch, 7. März 2012 01:52