1) Create a new windows application project
2) Drag a Datagrid view in Form
3) Create a simple MySql Table
4) Try the below code
private DataTable getTable()
{
MySqlCommand command = GetDatabaseConnection().CreateCommand();
MySqlDataAdapter mda = new MySqlDataAdapter();
DataTable dt = new DataTable();
command.CommandType = CommandType.Text;
string sqlStatement = "select * from table";
command.CommandText = sqlStatement;
mda.SelectCommand = command;
mda.SelectCommand.Connection = GetDatabaseConnection();
mda.Fill(dt);
command.Dispose();
return dt;
}
private void Form_Load(object sender, EventArgs e)
{
DataTable dTable = new Datatable;
dTable = datagridview1.Datasource;
}