我有一个MySqlDataReader对象,带有此查询的结果:
SELECT warehouse, leasing, transportation, maintenance, manpower FROM retail WHERE zone = 'Central' GROUP BY warehouse
然后我遍历DataReader一次,
while (r2.Read())
{
strXml.AppendFormat("<set label = '{0}'></set>",r2["warehouse"].ToString());
}
现在我想再次循环...... !!
我知道DataReader只是一个'仅限前瞻'的对象..但在这里有没有其他解决方案?
我问,是否有任何有效的方法来保存除MySqlDataReader以外的数据?
答案 0 :(得分:2)
您可以在下面使用:
using (MySqlConnection connMySql = new MySqlConnection(global.g_connString))
{
MySqlCommand cmd = connMySql.CreateCommand();
cmd.CommandText = "selece * from <table>";
connMySql.Open();
using (MySqlDataReader dr = cmd.ExecuteReader())
{
DataTable dt1 = new DataTable();
dt1.Load(dr);
// You can use this dt1 anywhere in the code
}
//解析数据表
DataTable dt = new DataTable();
if (dt.Rows.Count > 0)
{
for (int count = 0; count < dt.Rows.Count; count++)
{
string str= dt.Rows[count]["[ColumnName]"].ToString();
}
}