多くの調査の結果、この問題を提起した投稿は他に 1 つしかないことがわかりました。完全を期すために、ここに URL があります:
Webmatrix/Mono/MySQL を使用してレコードセットをループするときの結果が正しくない
さまざまな方法でテストした後、mono が sql クエリを正しく実行していないことが問題のようです。他の誰もこれを問題として記録していないようであることを考えると、これは私のインストールのバグであるとしか思えません。
とにかく、回避策として、他の人が興味を持っている場合に備えて、webgrid を使用するための私のソリューションを次に示します。
@using System.Collections;
@using System;
@using System.Data;
@using System.Data.SqlClient;
@using System.Dynamic;
@using System.Text;
@using System.Configuration;
@using MySql.Data.MySqlClient;
@{
//establish a connection to mysql db using the connection in web.config
MySqlConnection dbConn = new MySqlConnection(ConfigurationManager.ConnectionStrings["myStringName"].ConnectionString);
//====From here, source data is member table in database=====
//create a mysql command var to store the sql query and reference to the connection string
MySqlCommand command1 = new MySqlCommand("SELECT Id, Fname, Lname, Company, Email FROM ClientTable", dbConn);
//create a mysql adapter to call the command to be executed
MySqlDataAdapter dap1 = new MySqlDataAdapter(command1);
//create a dataset to capture the results of the sql query
DataSet dataset1 = new DataSet();
//use the adapter to fill data with the results of the query.
//ClientTable will be the name of the table in dataset.
dap1.Fill(dataset1, "ClientTable");
//iterate dataset to store its info into a list with columnnames
var clientProfile = new List<dynamic>();
foreach (DataRow dr in dataset1.Tables["ClientTable"].Rows)
{
var obj = (IDictionary<string, object>)new ExpandoObject();
foreach (DataColumn col in dataset1.Tables["ClientTable"].Columns)
{
obj.Add(col.ColumnName, dr[col.ColumnName]);
}
clientProfile.Add(obj);
}
WebGrid grid = new WebGrid(clientProfile, rowsPerPage:10);
}
<div id="xyz">
@grid.GetHtml(tableStyle : "gridtable",
alternatingRowStyle: "altRow")
</div>
それだけです。それが役に立つことを願っています。