.net C# 获得数据集行和列

Rows.Count  行

 using (SqlCommand cmd = Common.SqlCommand(sSqlString))
        {
            cmd.Connection.Open();
            SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
            sales_monthly_list.Load(dr);
            dr.Close();
        }


        for (var i = 0; i < sales_monthly_list.Rows.Count; ++i)
        {
DataRow s_fieldsvalue = sales_monthly_list.Rows[i];

        }

列:

using (SqlCommand cmd = Common.SqlCommand(sSqlString))
        {
            cmd.Connection.Open();
            SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
            while (dr.Read())
{
for (var i = 0; i < dr.FieldCount; ++i)
{
var name = (int)dr.GetName(i);  //得到列名
var chn = dr[1];
var mgr = dr[2];
scriptpush_share += Common.cstrln("push([" + id + ", '" + chn + "',"+mgr+"]);");
}
}
            dr.Close();
cmd.Connection.Close();
        }

posted @ 2012-12-19 15:28  y0umer  阅读(328)  评论(0编辑  收藏  举报