OleDbConnection cn = new OleDbConnection();
            cn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\`Hp\Desktop\PROGRAM1\notificationSystem\notificationSystem\Database.accdb";
            OleDbCommand cmd = new OleDbCommand();
            cmd.Connection = cn;

            //reg();

            cn.Open();
            cmd.CommandText = "select article from news where npublished = '" + metroDateTime1.Text + "' AND ntime = '" + label4.Text + "'";
            //AND ntime = '" + label4.Text + "'

            //Scalar executes the fetching of data
            var a = cmd.ExecuteScalar();

            //this statement gets the process of getting the data from the database to label          
            if (a != null)
            {
                label1.Text = "" + a.ToString();

                //while in this statement is displaying the data inside the textbox
                metroTextBox2.Text = label1.Text;
            }

            else if (metroTextBox2.Text != null)
            {

                //SEND SMS PROCESS
            }
            else if (metroTextBox2.Text == null)
            {
                //REPEAT FETCH
            }
            cn.Close();

So the code above works but i use a button, and i have to press the button everytime to fetch information. Does anyone have any advice on what should i do to automatically fetch information from database using datagridview and display it on textbox.

I want to put the code on form load, so everytime i will run the program it will automatically fetch and do its job. But i don't know how to do it and i tried but it won't work.

Any help is gradly appreciated.

WRONG THREAD POSTED.
PLEASE CLOSE THIS THREAD

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.