将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]]