0
 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.

1
Contributor
1
Reply
16
Views
1 Year
Discussion Span
Last Post by Tashia_1
0

WRONG THREAD POSTED.
PLEASE CLOSE THIS THREAD

Edited by Tashia_1

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.