转载C# Tutorials,ADO/adosample.cs
来源:互联网 发布:淘宝情侣装店铺推荐 编辑:程序博客网 时间:2024/05/17 07:41
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
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);
}
}<
转载C# Tutorials,ADO/ADOsample.cs';return true">
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
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);
}
}<
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 转载C# Tutorials,ADO/adosample.cs
- C# DX & HLSL tutorials
- C#,ADO封装,SqlHelper.cs
- 转载,CS-hello world
- c# ADO
- Tutorials
- Tutorials
- Tutorials
- Tutorials
- Tutorials
- c# cs 生成dll
- C# SQLHelper.cs
- [CS]C#操作word
- C# CookieHelper.cs!
- (转载)ADO技术
- 转载 ado用法
- 转载:计算机科学CS学科分类
- GTK+ layout management 转载http://zetcode.com/tutorials/gtktutorial/gtklayoutmanagement/
- c#写的五子棋程序,供学习WinForms的鼠标事件和使用GDI+,源码下载。
- Asp.net中用核选框显示数据的方法及ButtonColumn的使用方法
- 杏林同学录(四)
- 用asp.net向其他服务器post一条信息
- 杏林同学录(二)
- 转载C# Tutorials,ADO/adosample.cs
- DataBinding DropDownList
- 杏林同学录(一)
- 用PHP来写记数器(详细介绍)
- WebGain and HP Collaborate to Bridge Java and .NET
- 基于mysql的bbs设计(五)
- Singleton Pattern in CSharp
- 6。bbsd和cq66服务器端改造
- Finding a Control Inside a Template