MySQL with C#, from a PHP Developer's Standpoint
I understand that with PHP I can use mysql_query($sql); and mysql_fetch_array($result); to fetch some MySQL data and place it into an array. How is this achie开发者_如何学Cved in C# to where I could place my data in say, a datagrid?
This is probably the most quintessential ADO.NET code to fill DataGrid you're going to see (using disconnected DataSets, that is):
DataTable results = new DataTable();
using(MySqlConnection conn = new MySqlConnection(connString))
{
using(MySqlCommand command = new MySqlCommand(sqlQuery, conn))
{
MySqlDataAdapter adapter = new MySqlDataAdapter(command);
conn.Open();
adapter.Fill(results);
}
}
someDataGrid.DataSource = results;
someDataGrid.DataBind();
精彩评论