Sideway
output.to from Sideway
Draft for Information Only

Content

System.Data.OleDB
OleDbDataReader Class
 Definition
  In this article
 Examples
 Remarks
 Properties
 Methods
 Applies to
   .NET Core
   .NET Framework
   .NET Platform Extensions
   Xamarin.Mac
 See also
 Examples
 Source/Reference

System.Data.OleDB

The System.Data.OleDb namespace is the.NET Framework Data Provider for OLE DB.

OleDbDataReader Class

Definition

Namespace:
System.Data.OleDb
Assemblies:
System.Data.dll, System.Data.OleDb.dll

Provides a way of reading a forward-only stream of data rows from a data source. This class cannot be inherited.

In this article

  1. Definition
  2. Examples
  3. Remarks
  4. Properties
  5. Methods
  6. Applies to
  7. See also
C#
public sealed class OleDbDataReader : System.Data.Common.DbDataReader
Inheritance
Object MarshalByRefObject OleDbDataReader

Examples

The following example creates an OleDbConnection, an OleDbCommand, and an OleDbDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the OleDbDataReader and then the OleDbConnection.

C#
public static void ReadData(string connectionString, string queryString)
{
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        OleDbCommand command = new OleDbCommand(queryString, connection);

        connection.Open();
        OleDbDataReader reader = command.ExecuteReader();

        while (reader.Read())
        {
            Console.WriteLine(reader[0].ToString());
        }
        reader.Close();
    }
}

Remarks

To create an OleDbDataReader, you must call the ExecuteReader method of the OleDbCommand object, instead of directly using a constructor.

Before you close the OleDbConnection, first close the OleDbDataReader object. You must also close the OleDbDataReader object if you plan to resuse an OleDbCommand object.For example, you cannot retrieve output parameters until after you call Close.

Changes made to a result set by another process or thread while data is being read may be visible to the user of the OleDbDataReader. However, the precise behavior is timing dependent.

IsClosed and RecordsAffected are the only properties that you can call after the OleDbDataReader is closed. Although the RecordsAffected property may be accessed while the OleDbDataReader exists, always call Close before returning the value of RecordsAffected to guarantee an accurate return value.

Properties

Depth

Gets a value that indicates the depth of nesting for the current row.

FieldCount

Gets the number of columns in the current row.

HasRows

Gets a value that indicates whether the OleDbDataReader contains one or more rows.

IsClosed

Indicates whether the data reader is closed.

Item[Int32]

Gets the value of the specified column in its native format given the column ordinal.

Item[String]

Gets the value of the specified column in its native format given the column name.

RecordsAffected

Gets the number of rows changed, inserted, or deleted by execution of the SQL statement.

VisibleFieldCount

Gets the number of fields in the OleDbDataReader that are not hidden.

Methods

Close()

Closes the OleDbDataReader object.

CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBoolean(Int32)

Gets the value of the specified column as a Boolean.

GetByte(Int32)

Gets the value of the specified column as a byte.

GetBytes(Int32, Int64, Byte[], Int32, Int32)

Reads a stream of bytes from the specified column offset into the buffer as an array starting at the given buffer offset.

GetChar(Int32)

Gets the value of the specified column as a character.

GetChars(Int32, Int64, Char[], Int32, Int32)

Reads a stream of characters from the specified column offset into the buffer as an array starting at the given buffer offset.

GetData(Int32)

Returns an OleDbDataReader object for the requested column ordinal.

GetDataTypeName(Int32)

Gets the name of the source data type.

GetDateTime(Int32)

Gets the value of the specified column as a DateTime object.

GetDecimal(Int32)

Gets the value of the specified column as a Decimal object.

GetDouble(Int32)

Gets the value of the specified column as a double-precision floating-point number.

GetEnumerator()

Returns an IEnumerator that can be used to iterate through the rows in the data reader.

GetFieldType(Int32)

Gets the Type that is the data type of the object.

GetFloat(Int32)

Gets the value of the specified column as a single-precision floating-point number.

GetGuid(Int32)

Gets the value of the specified column as a globally unique identifier (GUID).

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetInt16(Int32)

Gets the value of the specified column as a 16-bit signed integer.

GetInt32(Int32)

Gets the value of the specified column as a 32-bit signed integer.

GetInt64(Int32)

Gets the value of the specified column as a 64-bit signed integer.

GetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetName(Int32)

Gets the name of the specified column.

GetOrdinal(String)

Gets the column ordinal, given the name of the column.

GetSchemaTable()

Returns a DataTable that describes the column metadata of the OleDbDataReader.

GetString(Int32)

Gets the value of the specified column as a string.

GetTimeSpan(Int32)

Gets the value of the specified column as a TimeSpan object.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetValue(Int32)

Gets the value of the column at the specified ordinal in its native format.

GetValues(Object[])

Populates an array of objects with the column values of the current row.

InitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
IsDBNull(Int32)

Gets a value that indicates whether the column contains nonexistent or missing values.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
NextResult()

Advances the data reader to the next result, when reading the results of batch SQL statements.

Read()

Advances the OleDbDataReader to the next record.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

.NET Core

3.0 Preview 7

.NET Framework

4.8 4.7.2 4.7.1 4.7 4.6.2 4.6.1 4.6 4.5.2 4.5.1 4.5 4.0 3.5 3.0 2.0 1.1

.NET Platform Extensions

3.0 Preview 7

Xamarin.Mac

3.0

See also

Examples

Examples of OleDbDataReader Class
ASP.NET Code Input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
       <title>Sample Page</title>
       <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
       <script runat="server" >
           Sub Page_Load()
               Dim xstr As String
               
               Dim xconn As System.Data.OleDb.OleDbConnection = new System.Data.OleDb.OleDbConnection()
               Dim xcomm As System.Data.OleDb.OleDbCommand = new System.Data.OleDb.OleDbCommand()
               xconn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=T:\test.mdb;User Id=admin;Password=;"
               xconn.Open()
               xstr = xstr + "Database test.mdb connection xconn is opened successfully.<br />"
               xcomm.Connection = xconn
               xstr = xstr + "Command Connection: " & xcomm.Connection.ToString & "<br />"
               xcomm.CommandText = "Select * from t1"
               xstr = xstr + "Command Text: " & xcomm.CommandText & "<br />"
               Dim xreader As System.Data.OleDb.OleDbDataReader = xcomm.ExecuteReader()
               xstr = xstr + "DataReader xreader is assigned successfully.<br />"
               xstr = xstr & "DataReader xreader.IsClosed  is " & xreader.IsClosed & "<br />"
               xstr = xstr & "Fieldcount of current row is " & xreader.FieldCount & "<br />"
               xstr = xstr & "Fieldname xreader.GetName(0) is " & xreader.GetName(0) & "<br />"
               xstr = xstr & "Fieldnumber xreader.GetOrdinal(""f1"") is " & xreader.GetOrdinal("f1") & "<br />"
               xstr = xstr & "Depth of xreader is " & xreader.Depth & "<br />"
               xstr = xstr & "Reader xreader.HasRows is " & xreader.HasRows & "<br />"
               xstr = xstr & "Reader xreader.Read() is " & xreader.Read() & "<br />"
               xstr = xstr & "Reader xreader.HasRows is " & xreader.HasRows & "<br />"
               xstr = xstr & "Depth of xreader is " & xreader.Depth & "<br />"
               xstr = xstr & "Field xreader(0) is " & xreader(0).ToString & "<br />"
               xstr = xstr & "Field xreader.GetString(1) is " & xreader.GetString(1) & "<br />"
               xstr = xstr & "Field xreader.item(2) is " & xreader.item("f2") & "<br />"
               xstr = xstr & "Field xreader.item(""f2"") is " & xreader.item("f2") & "<br />"
               xstr = xstr & "Reader xreader.Read() is " & xreader.Read() & "<br />"
               xstr = xstr & "Depth of xreader is " & xreader.Depth & "<br />"
               xstr = xstr & "Field xreader.item(2) is " & xreader.item("f2") & "<br />"
               xstr = xstr & "Reader xreader.NextResult() is " & xreader.NextResult() & "<br />"
               xreader.close()
               xstr = xstr & "DataReader xreader.IsClosed  is " & xreader.IsClosed & "<br />"
               xstr = xstr & "Reader xreader is closed successfully.<br />"
               xconn.Close()
               xstr = xstr + "Database test.mdb connection xconn is closed successfully.<br />"
               xconn.Dispose()
               xstr = xstr + "Database test.mdb connection xconn is disposed successfully."
               lbl01.Text = xstr
           End Sub
       </script>
    </head>
    <body>
<%Response.Write("<p>Results on "& Request.ServerVariables("SERVER_SOFTWARE") & " .net: " & System.Environment.Version.ToString & " " & ScriptEngine & " Version " & ScriptEngineMajorVersion & "." & ScriptEngineMinorVersion & "</p>")%>
       <% Response.Write ("<h1>This is a Sample Page of OleDbDataReader Class</h1>") %>
       <p>
           <%-- Set on Page_Load --%>
           <asp:Label id="lbl01" runat="server" />
       </p>
    </body>
</html>
HTML Web Page Embedded Output:

Source/Reference


©sideway

ID: 201000029 Last Updated: 29/10/2020 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 337

Reference 67

Computer

Hardware 151

Software

Application 198

Digitization 25

Latex 9

Manim 122

Numeric 19

Programming

Web 285

Unicode 494

HTML 65

CSS 59

ASP.NET 194

OS 391

DeskTop 7

Python 23

Knowledge

Mathematics

Formulas 8

Algebra 29

Number Theory 206

Trigonometry 18

Geometry 21

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Physics

Electric 27

Biology 1

Geography 1


Copyright © 2000-2020 Sideway . All rights reserved Disclaimers last modified on 06 September 2019