开发者

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜