⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 schematable.cs

📁 Csharp实例编程百例.rar
💻 CS
字号:
using System;
using System.Data;
using System.Data.OleDb;

namespace SchemaTableApp
{
	class SchemaTable
	{
		static void Main(string[] args)
		{
			string ConStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\C#Program\C#100\Chapter3\NWIND.mdb";

			// Pass connection string to the connection object 
			OleDbConnection connection = new OleDbConnection(ConStr);

			try
			{
				connection.Open();

				OleDbCommand command = new OleDbCommand("SELECT * FROM Employees",connection);
				OleDbDataReader dataReader = command.ExecuteReader();

				// Store the data structure of the Employees table in a DataTable
				DataTable schemaTable = dataReader.GetSchemaTable();

				/* Display data structure info of each row in the 
				 * returned DataTable, which describes
				 * one column in the original table */
				foreach (DataRow dRow in schemaTable.Rows)
				{
					foreach (DataColumn dCol in schemaTable.Columns)
						Console.WriteLine(dCol.ColumnName + " = " + dRow[dCol]);
					Console.WriteLine("----------------");
				}

				dataReader.Close();
			}
			catch(Exception ex)
			{
				Console.WriteLine("Error Orccured: " + ex.Message);
			}
			finally
			{
				connection.Close();
				Console.ReadLine();
			}
		}  
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -