本文整理汇总了C#中System.Data.OleDb.OleDbDataReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# OleDbDataReader.Read方法的具体用法?C# OleDbDataReader.Read怎么用?C# OleDbDataReader.Read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.OleDb.OleDbDataReader
的用法示例。
在下文中一共展示了OleDbDataReader.Read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadData
private static void ReadData(string connectionString)
{
string queryString = "SELECT OrderID, CustomerID FROM Orders";
using (OracleConnection connection = new OracleConnection(connectionString))
{
OracleCommand command = new OracleCommand(queryString, connection);
connection.Open();
OracleDataReader reader;
reader = command.ExecuteReader();
// Always call Read before accessing data.
while (reader.Read())
{
Console.WriteLine(reader.GetInt32(0) + ", " + reader.GetString(1));
}
// Always call Close when done reading.
reader.Close();
}
}
示例2: OleDbDataReader.Read()
//引入命名空间
using System;
using System.Data;
using System.Data.OleDb;
class MainClass
{
static void Main(string[] args)
{
string connString = "provider=sqloledb;server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI";
string sql = @"select * from employee";
OleDbConnection conn = null;
OleDbDataReader reader = null;
try
{
conn = new OleDbConnection(connString);
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql, conn);
reader = cmd.ExecuteReader();
Console.WriteLine("Querying database {0} with query {1}\n", conn.Database, cmd.CommandText );
while(reader.Read()) {
Console.WriteLine("{0} | {1}", reader["FirstName"].ToString().PadLeft(10), reader[1].ToString().PadLeft(10));
}
}
catch (Exception e)
{
Console.WriteLine("Error: " + e);
}
finally
{
reader.Close();
conn.Close();
}
}
}