Alex Rivera | Logout

How can I connect to MySQL from windows forms?

Asked 2009-07-09T05:25:38.420
10

How can I connect to a MySQL database from Windows Forms?

Edit
Report

1 Answer

1
private void button1_Click(object sender, System.EventArgs e)
{
    string MyConString = "SERVER=localhost;" +"DATABASE=mydatabase;" 
        "UID=testuser;" +"PASSWORD=testpassword;";
    MySqlConnection connection = new MySqlConnection(MyConString);
    MySqlCommand command = connection.CreateCommand();
    MySqlDataReader Reader;
    command.CommandText = "select * from mycustomers";
    connection.Open();
    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);
    }
    connection.Close(); 
}

i think this gonna be the simple one right!!! but thanx all of u guys for responding and providing me the documentation!

answered 2009-07-09T05:49:49.200

Your Answer