乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      數(shù)據(jù)集處理技術 DataReader DataTable DataSet 之間的轉換

       青格兒 2009-03-19
            
      http://www.cnblogs.com/binarytree/archive/2008/10/09/1306843.html

             綁定Gridview里往往數(shù)據(jù)源是DataSet 或是DataTable 嗯 ,一些類庫(SQLHelper等)里面的方法返回的是DataReader嗯 ,怎么把它們轉成DataSet呢?

      (1)

      DataReader轉為DataSet的類:

       

      private   DataSet   DataReaderToDataSet(IDataReader   reader)    

        {    

        DataTable   table   =   new   DataTable();    

        int   fieldCount   =   reader.FieldCount;     

        for   (int   i   =   0;   i   <   fieldCount;   i++)    

        {    

        table.Columns.Add(reader.GetName(i),   reader.GetFieldType(i));    

        }    

        table.BeginLoadData();    

        object[]   values   =   new   object[fieldCount];    

        while   (reader.Read())    

        {    

        reader.GetValues(values);    

        table.LoadDataRow(values,   true);    

        }    

        table.EndLoadData();    

        DataSet   ds   =   new   DataSet();    

        ds.Tables.Add(table);    

        return   ds;    

        }

       

      (2)

      :DataAdapterDataReader是不同的哦

      DataAdapter可以這樣做:

      DataAdapter.Fill(ds)
       
      (3)
      #region DataReader轉換為DataTable
        
              /// </summary>
              /// <param name="reader"></param>
              /// <returns></returns>
              public static DataTable ConvertDataReaderToDataTable(SqlDataReader reader)
              {
                  try
                  {
                      DataTable objDataTable = new DataTable();
                      int intFieldCount = reader.FieldCount;
                      for (int intCounter = 0; intCounter < intFieldCount; ++intCounter)
                      {
                          objDataTable.Columns.Add(reader.GetName(intCounter), reader.GetFieldType(intCounter));
                      }

                      objDataTable.BeginLoadData();

                      object[] objValues = new object[intFieldCount];
                      while (reader.Read())
                      {
                          reader.GetValues(objValues);
                          objDataTable.LoadDataRow(objValues, true);
                      }
                      reader.Close();
                      objDataTable.EndLoadData();

                      return objDataTable;

                  }
                  catch (Exception ex)
                  {
                      throw new Exception("轉換出錯!", ex);
                  }
              }
              #endregion
       
      DataTable緩存數(shù)據(jù)操作:
       
       
      如何將SqlDataReader綁定到DataGrid
       
       
      C#中提供的精準測試程序運行時間的類Stopwatch
       
       
      c#中連接數(shù)據(jù)庫SqlDataAdapter的用法
       
       
      SqlDataAdapter它的用法有很多,比DataReader強大多了,感興趣的朋友可以查查。DataReader是只讀的,也就是單向的。而適配器呢,它既可以讀又可以寫。
       
       
      讀取Excel內(nèi)容,導入數(shù)據(jù)庫多張表!
       
       

        本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊一鍵舉報。
        轉藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多