标题:将DataTable转换为二维数组的方法
只看楼主
foshan
Rank: 1
等 级:新手上路
威 望:2
帖 子:605
专家分:0
注 册:2006-3-1
结帖率:100%
 问题点数:0 回复次数:0 
将DataTable转换为二维数组的方法
public string[,] DataTableToArray()//将DataTable转换为二维数组
        {
            SqlConnection conn = new SqlConnection("data source=(local);database=********;user=********; password=********");
            DataSet ds = new DataSet();
            string MySql = "select HeTongXinXi.jsID,gcmc,sgdw,htjj,kgrq,nsrq,jhsqrq,sjsqrq,bz1 from HeTongXinXi"
                         + " left join ydwcck on HeTongXinXi.jsID=ydwcck.jsID and ydwcck.rq = '" + DateTime.Now.Year.ToString() + "年" + DateTime.Today.Month.ToString() + "月'"
                         + " left join jsck on HeTongXinXi.jsID=jsck.htid"
                         + " where xiangmumingchenID = '1/54/56'"
                         + " order by HeTongBianHao";
            SqlDataAdapter da2 = new SqlDataAdapter(MySql, conn);
            da2.Fill(ds, "HeTongXinXi");
            System.Data.DataTable dt = ds.Tables[0];
            int i = 0;
            int rowsCount = dt.Rows.Count;
            int colsCount = dt.Columns.Count;
            string[,] arrReturn = new string[rowsCount, colsCount];
            foreach (System.Data.DataRow row in dt.Rows)
            {
                i = i++;
                int j = 0;
                foreach (System.Data.DataColumn column in dt.Columns)
                {
                    j = j++;
                    arrReturn[i, j] = row[column.ColumnName].ToString();
                }
            }
            return arrReturn;
        }

[[it] 本帖最后由 foshan 于 2008-2-2 08:20 编辑 [/it]]
搜索更多相关主题的帖子: DataTable 
2008-01-31 09:41



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-199158-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.154438 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved