program.cs
来自「讲述如何使用c#访问关系数据库」· CS 代码 · 共 51 行
CS
51 行
#region Using directives
using System;
using System.Data; // Use ADO.NET namespace
using System.Data.OleDb; // Use namespace for OLE DB .NET Data Provider
using System.Collections.Generic;
using System.Text;
#endregion
namespace ReadingAccessData
{
class Program
{
static void Main(string[] args)
{
// Create connection object for Microsoft Access OLE DB Provider;
// note @ sign prefacing string literal so backslashes in path name;
// work
OleDbConnection thisConnection = new OleDbConnection(
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\tmp\nwind.mdb");
// Open connection object
thisConnection.Open();
// Create SQL command object on this connection
OleDbCommand thisCommand = thisConnection.CreateCommand();
// Initialize SQL SELECT command to retrieve desired data
thisCommand.CommandText =
"SELECT CustomerID, CompanyName FROM Customers";
// Create a DataReader object based on previously defined command object
OleDbDataReader thisReader = thisCommand.ExecuteReader();
while (thisReader.Read())
{
Console.WriteLine("\t{0}\t{1}",
thisReader["CustomerID"], thisReader["CompanyName"]);
}
thisReader.Close();
thisConnection.Close();
Console.Write("Program finished, press Enter/Return to continue:");
Console.ReadLine();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?