Displaying Mysql database data into listbox using C# asp.net


Getting Data from Mysql to listbox in c#
Showing Data in listbox inc#

Program:-

string MyConString = "SERVER=localhost;" +
                "DATABASE=speed;" +
                "UID=root;" +
                "PASSWORD=test;";

/* speed is database name, root is mysql username, test is mysql password */

MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand()

// open connection
connection.Open();

// entry is mysql table name
 MySqlDataReader Reader;

 command.CommandText = "SELECT * FROM `entry`";
 Reader = command.ExecuteReader();

                while (Reader.Read())
                {
                    string thisrow = "";
                    for (int i = 0; i < Reader.FieldCount; i++)
                        thisrow += Reader.GetValue(i).ToString() + ",";
                    ListBox1.Items.Add(thisrow);
                }

//close connection
connection.Close();

Output:-


Leave reply

Add your comments here

Back to Top