国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

轉載C# Tutorials,ADO/adosample.cs

2024-07-21 02:25:35
字體:
來源:轉載
供稿:網友
using system;
using system.data;
using system.data.ado;

public class mainclass
{
   public static void main ()
   {
      // set access connection and select strings
      string straccessconn = "provider=microsoft.jet.oledb.4.0;data source=bugtypes.mdb";
      string straccessselect = "select * from categories";

      //create the dataset and add the categories table to it
      dataset mydataset = new dataset();
      mydataset.tables.add("categories");
      
      // create my access objects
      adoconnection myaccessconn = new adoconnection(straccessconn);
      adodatasetcommand myaccessdatasetcmd = new adodatasetcommand();
      myaccessdatasetcmd.selectcommand = new adocommand(straccessselect,myaccessconn);

      myaccessconn.open();
      try
      {
         myaccessdatasetcmd.filldataset(mydataset,"categories");
      }
      finally
      {
         myaccessconn.close();
      }

      try
      {
         /* a dataset can contain multiple tables,
           so let's get them all into an array */
         datatable[] dta = mydataset.tables.all;
         foreach (datatable dt in dta)
         {
            console.writeline("found data table {0}", dt.tablename);
         }
         
         /* the next two lines show two different ways
            you can get the count of tables in a dataset */
         console.writeline("{0} tables in data set", mydataset.tables.count);
         console.writeline("{0} tables in data set", dta.length);
         /* the next several lines show how to get information
            on a specific table by name from the dataset */
         console.writeline("{0} rows in categories table", mydataset.tables["categories"].rows.count);
         /* the column info is automatically fetched from the
            database, so we can read it here */
         console.writeline("{0} columns in categories table", mydataset.tables["categories"].columns.count);
         datacolumn[] drc = mydataset.tables["categories"].columns.all;
         int i = 0;
         foreach (datacolumn dc in drc)
         {
            /* print the column subscript, then the
               column's name and its data type */
            console.writeline("column name[{0}] is {1}, of type {2}",i++ , dc.columnname, dc.datatype);
         }
         datarow[] dra = mydataset.tables["categories"].rows.all;
         foreach (datarow dr in dra)
         {
            /* print the categoryid as a subscript,
               then the categoryname */
            console.writeline("categoryname[{0}] is {1}", dr[0], dr[1]);
         }
      }
      catch (exception e)
      {
         console.writeline("oooops.  caught an exception:/n{0}", e.message);
      }
   }
}
  • 本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。
  • 發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 观塘区| 雷波县| 凤山市| 当涂县| 云浮市| 邵东县| 罗城| 中江县| 镇康县| 葵青区| 石嘴山市| 凌云县| 三亚市| 壤塘县| 黄龙县| 贵港市| 望江县| 南华县| 临澧县| 翁牛特旗| 抚顺市| 芦山县| 通河县| 郴州市| 长宁县| 新巴尔虎左旗| 郎溪县| 奇台县| 勃利县| 藁城市| 赞皇县| 伊吾县| 珠海市| 玉山县| 鄂托克前旗| 农安县| 仪陇县| 贡山| 施秉县| 淳化县| 贡山|