<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    風人園

    弱水三千,只取一瓢,便能解渴;佛法無邊,奉行一法,便能得益。
    隨筆 - 99, 文章 - 181, 評論 - 56, 引用 - 0
    數(shù)據(jù)加載中……

    c#行列轉(zhuǎn)換

    寫了一天,做出來才知道沒有那么難。
    我還向我的朋友求助,向主任請教,獲得了很多版本,下面我把代碼列出,和大家一起分享。
    我要感謝我的朋友和他的項目經(jīng)理,還有我的主任。
    ?
    第一版
    #region change hang lie in DataSet out DataSet?
    ???????
    ??public? DataSet changehl(DataSet mm)
    ??{
    ???try
    ????? {
    ???????int h=mm.Tables[0].Rows.Count;
    ?????? int l=mm.Tables[0].Columns.Count;????
    ?????? DataSet myDataSet = new DataSet();
    ?????? DataTable namesTable= new DataTable();????????
    ?????? for(int i=0; i<h; i++)
    ?????? {?
    ?????? ?namesTable.Columns.Add(mm.Tables[0].Rows[i][0].ToString ());
    ????????}?????????
    ?????? for(int i=0;i<l;i++)
    ????? ?{?????
    ?????? ?DataRow r;
    ??????? r=namesTable.NewRow();?????????
    ??????? for(int j=0;j<h;j++)????
    ????? ?{???????
    ?????? ?r[j] = mm.Tables[0].Rows[j][i].ToString();?????????
    ?????? }
    ??????? if (i==0)
    ?????? ?{}
    ?????? ?else
    ?????? {
    ?????? ?namesTable.Rows.Add(r);?
    ?????? }
    ????}
    ????myDataSet.Tables.Add(namesTable);??????
    ???????
    ????return myDataSet;
    ???}???
    ???catch(Exception ex)
    ???{
    ????return mm ;
    ????}
    ???
    ??}
    ??#endregion
    ?
    ?
    第二版
    ?
    #region change hang lie in DataGrid out DataSet?
    ?
    private DataSet dataGridChangeRC(DataGrid ss )
    ??{
    ???DataSet myDataSet = new DataSet();
    ???try
    ???{
    ????int h=ss.Items.Count;
    ????int l=ss.Items[0].Cells.Count;
    ????string[,] ary=new string[h,l];
    ????for(int i=0;i<h;i++)
    ????{
    ?????for(int j=0;j<l;j++)
    ?????{
    ??????ary[i,j]=ss.Items[i].Cells[j].Text.Trim().ToString () ;
    ?????}
    ????}
    ????DataTable namesTable= new DataTable();?
    ????for(int i=0; i<h; i++)
    ????{?
    ?????namesTable.Columns.Add(ary[i,0]);
    ????}?
    ????for(int i=0;i<l;i++)
    ????{?????
    ?????DataRow r;
    ?????r=namesTable.NewRow();?????????
    ?????for(int j=0;j<h;j++)????
    ?????{???????
    ??????r[j] = ary[j,i];???????
    ?????}
    ?????if (i==0)
    ?????{}
    ?????else
    ?????{
    ??????namesTable.Rows.Add(r);?
    ?????}
    ????}
    ????myDataSet.Tables.Add(namesTable);??????
    ????return myDataSet;
    ???}
    ???catch(Exception ex)
    ???{
    ??? ???return myDataSet;
    ???}
    ??}
    ?#endregion
    ?
    第三版

    ??using System;
    ??using System.Collections.Generic;
    ??using System.ComponentModel;
    ??using System.Data;
    ??using System.Drawing;
    ??using System.Text;
    ??using System.Windows.Forms;
    ??namespace Win_form
    ??{
    ???? public partial class DataSet : Form
    ???????? {
    ????????? public DataSet()
    ????????? {
    ?????????? InitializeComponent();
    ????????? }
    ????????? #region change hang lie

    ????????? public static DataSet changehl(DataSet mm)
    ????????? {
    ?????????? try
    ?????????? {
    ??????????? int sourceRowsCount = mm.Tables[0].Rows.Count;
    ??????????? int sourceColumnsCount = mm.Tables[0].Columns.Count;
    ??????????? DataSet destinationDataSet = new DataSet();
    ??????????? DataTable destinationTable = new DataTable();
    ??????????? #region initialize destination table
    ??????????? for (int i = 0; i < sourceRowsCount; i++)
    ??????????? {
    ??????????? destinationTable.Columns.Add(Convert.ToString(i));
    ??????????? }
    ??????????? destinationTable.Rows.Count = sourceColumnsCount;
    ??????????? #endregion
    ??????????? #region reverse source table to destination table Using Two Dimension Matrix Reverse Arithmetic
    ??????????? int dcIndex;//the column number of each destination table row
    ??????????? int srIndex;//the row number of each source table column
    ??????????? int drIndex;
    ??????????? int scIndex;
    ??????????? for (dcIndex = 0, srIndex = 0;
    ???????????? dcIndex < destinationTable.Columns.Count
    ???????????? && srIndex < sourceRowsCount; dcIndex++, srIndex++)
    ??????????? {
    ???????????? for (drIndex = 0,scIndex=0;
    ????????????? drIndex < destinationTable.Rows.Count
    ????????????? && scIndex < sourceColumnsCount; drIndex++, scIndex++)
    ???????????? {
    ????????????? destinationTable.Rows[drIndex][dcIndex] = mm.Tables[0].Rows[srIndex][scIndex];
    ???????????? }
    ??????????? }
    ??????????? #endregion
    ??????????? destinationDataSet.Tables.Add(destinationTable);
    ??????????? return destinationDataSet;
    ?????????? }
    ?????????? catch (Exception ex)
    ?????????? {
    ??????????? MessageBox.Show(ex.ToString());
    ?????????? }
    ????????? }
    ????????? #endregion
    ???????? }
    ??}
    ?
    第四版
    ?
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    namespace DataSetConvert
    {
    ??? public partial class Form1 : Form
    ??? {
    ??????? public Form1()
    ??????? {
    ??????????? InitializeComponent();
    ??????? }
    ??????? private void RowtoCollumn()
    ??????? {
    ??????????? DataSet sourceDataSet = new DataSet();
    ??????????? DataSet destinationDataSet = new DataSet();
    ??????????? int sourceRowCount = sourceDataSet.Tables[0].Rows.Count;
    ??????????? int destinationColCount = sourceRowCount;
    ??????????? int sourceColCount = sourceDataSet.Tables[0].Columns.Count;
    ??????????? int destinationRowCount = sourceColCount;
    ??????????? for(int i=0;i<destinationRowCount;i++)
    ??????????????????? for (int j=0; j < destinationColCount; j++)
    ??????????????????? {
    ??????????????????????? destinationDataSet.Tables[0].Rows[i][j]=sourceDataSet.Tables[0].Rows[j][i];
    ??????????????????? }??
    ????????
    ???????? }
    ??? }
    }
    ?
    第一版和第二版是基于 web做的第一版可以做為class和dll?第二版只可以做class?我試過生成dll 不行 第三版和第四版 是我朋友和他的項目經(jīng)理做的 是在windows form 中做的

    posted on 2007-03-09 10:03 風人園 閱讀(1374) 評論(0)  編輯  收藏 所屬分類: DotNet

    主站蜘蛛池模板: 香蕉免费在线视频| 亚洲一区二区三区无码国产| 亚洲性在线看高清h片| 天天摸夜夜摸成人免费视频 | 久久精品国产亚洲AV无码偷窥| 亚洲国产a∨无码中文777| 久久青青草原亚洲av无码| 国产亚洲视频在线播放| 亚洲色欲色欲www在线丝 | 2021国产精品成人免费视频| 国产免费丝袜调教视频| 欧洲乱码伦视频免费| 毛片免费视频播放| 成人毛片免费观看视频大全| 成人免费视频小说| 国产成人免费网站在线观看| 俄罗斯极品美女毛片免费播放| 亚洲国产精品国产自在在线| 国产亚洲精品AA片在线观看不加载 | 国产成人无码区免费网站| 久久亚洲免费视频| 亚洲黄色免费电影| 成人毛片视频免费网站观看| 免费人妻无码不卡中文字幕18禁| 亚洲精品乱码久久久久久不卡| 亚洲精品午夜国产VA久久成人| 亚洲AV乱码一区二区三区林ゆな| 亚洲自偷精品视频自拍| 日韩亚洲国产综合高清| 国产成人精品亚洲一区| v片免费在线观看| 午夜精品免费在线观看| 国产一卡2卡3卡4卡无卡免费视频| 免费观看的毛片手机视频| 免费99热在线观看| 亚洲精品亚洲人成人网| 精品久久亚洲中文无码| 日韩在线观看免费完整版视频| 亚洲精品免费观看| 免费黄色一级毛片| 亚洲色爱图小说专区|