none
how can i Rahu, Pankaj, Rani..... with data table column "StudenName" using MS Access RRS feed

  • General discussion

  • namespace demo3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                string strDatabase = @"Provider = Microsoft.jet.OleDb.4.0; Data Source = G:\\Galaxy\\SchoolGalaxy\\GalaxyData.mdb";
                string strTableStudentInfo = "SELECT StudentName FROM StudInfo";
                OleDbConnection myConnection = new OleDbConnection(strDatabase);
                OleDbDataAdapter myDA = new OleDbDataAdapter(strTableStudentInfo, strDatabase);
                OleDbCommandBuilder myCB = new OleDbCommandBuilder(myDA);
                DataSet myDS = new DataSet();
                
                
                //OleDbCommand myCommand = new OleDbCommand(strTableStudentInfo);
                //myCommand.Connection = myConnection;
                myConnection.Open();
                //OleDbDataReader myreader = myCommand.ExecuteReader();
                AutoCompleteStringCollection source = new AutoCompleteStringCollection();
                //source.AddRange(new string[]
                  //  {
                    //    "Rahul",
                      //  "aruna",
                        //"shilpa",
                        //"amol",
                        //"Pragati",
                      //  "pankaj",
                       // "pradeep",
                        //"Rani",
                    //});
                source.AddRange(new string[] 
                                {
                                    
                                });
                //myreader.Close();
                // Create and initialize the text box.
                this.textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
                this.textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
                this.textBox1.AutoCompleteCustomSource = source;
            }
        }
    }

    Friday, June 15, 2012 6:01 AM

All replies

  • I got it, the code is:

    namespace demo3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                string strDatabase = @"Provider = Microsoft.jet.OleDb.4.0; Data Source = G:\\Galaxy\\SchoolGalaxy\\GalaxyData.mdb";
                string strTableStudentInfo = "SELECT distinct [StudentName] FROM [StudInfo]" + "ORDER BY [StudentName] asc";
                OleDbConnection myConnection = new OleDbConnection(strDatabase);
                OleDbCommand myCommand = new OleDbCommand(strTableStudentInfo);
                myCommand.Connection = myConnection;
                myCommand.CommandType = CommandType.Text;
                myCommand.CommandText = strTableStudentInfo;
                myConnection.Open();
                OleDbDataReader myreader = myCommand.ExecuteReader();
                AutoCompleteStringCollection source = new AutoCompleteStringCollection();
                //source.AddRange(new string[]
                  //  {
                    //    "Rahul",
                      //  "aruna",
                        //"shilpa",
                        //"amol",
                        //"Pragati",
                      //  "pankaj",
                       // "pradeep",
                        //"Rani",
                    //});
                if (myreader.HasRows == true)
                {
                    while (myreader.Read())
                        source.Add(myreader["StudentName"].ToString());
                }
                else
                {
                    MessageBox.Show("Data not found");
                }
               
                myreader.Close();
                // Create and initialize the text box.
                this.textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
                this.textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
                this.textBox1.AutoCompleteCustomSource = source;
            }
        }
    }


    Friday, June 15, 2012 6:24 PM
  • Rahul,

    Make from your discussion in top of your first message a question. 

    Then mark your own reply as answer, then we know this thread is done.

    Thanks



    Cor


    Monday, June 18, 2012 6:15 AM