ch10_03.cs
来自「《c#技术内幕代码》」· CS 代码 · 共 50 行
CS
50 行
using System;
using System.Data;
using System.Data.ADO;
public class CH10_2
{
public static void Main ()
{
// Define the connection string
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND.MDB";
// Define our selection criteria
string strRec = "SELECT * FROM Employees ORDER by LastName";
// Create the connection object, using our connection string
ADOConnection myConn = new ADOConnection(strConn);
// Create the command object from our selection criteria string
ADOCommand myCmd = new ADOCommand( strRec, myConn );
// Try to execute the command
ADODataReader outData = null;
try
{
// This will do the connection to the database
myConn.Open();
// This will run our query and put the result in outData
myCmd.Execute( out outData );
// See if we got something back
if ( outData != null )
{
while (outData.Read() )
{
Console.WriteLine( "Last Name: {0}", outData["LastName"]);
}
}
}
catch ( Exception e )
{
Console.WriteLine("Exception {0}", e );
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?