| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1310 人关注过本帖
标题:将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
快速回复:将DataTable转换为二维数组的方法
数据加载中...
 
   



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

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