Dynamicweb 8 Documentation
CreateDataReader(String) Method
Example 

The SQL specifiyng the data to return in the DataReader
Creates a DataReader by sending the sql to the Connection and build an IDataReader.
Syntax
'Declaration
 
Public Overloads Shared Function CreateDataReader( _ 
   ByVal sql As String _ 
) As IDataReader
public static IDataReader CreateDataReader( 
   string sql 
)

Parameters

sql
The SQL specifiyng the data to return in the DataReader

Return Value

Datareader instance - OleDBReader for Access solutions and SqlDbReader for SQl-Server based solutions.
Remarks
Connects to the default database. Dynamic.mdb in /Database if the solution is running MS Access, or the SQL-Server database if the solution is running MS SQL-Server. The underlying connection will close itself after the reader is closed and disposed.
Example
Create a DataReaderCreate a DataReader
namespace Dynamicweb.Examples.CSharp
{
    class DatabaseCreateDataReader
    {

        public void DataReaderSample()
        {
            //Create a DataReader on the default database
            using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM Page"))
            {
                while (myDr.Read())
                {
                    var pageId = Input.FormatInteger(myDr["PageID"]);
                }
            }

            //Create a DataReader on alternate database
            using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM AccessUser", "Access.mdb"))
            {
                while (myDr.Read())
                {
                    var pageId = Input.FormatInteger(myDr["AccessUserID"]);
                }
            }

        }

    }
}
Public Class DatabaseCreateDataReader

    Public Sub DataReaderSample()

        'Create a DataReader on the default database
        Using myDr As IDataReader = Database.CreateDataReader("SELECT TOP 10 * FROM Page")
            Do While myDr.Read
                Dim pageId As Integer = Input.FormatInteger(myDr.Item("PageID"))
            Loop
        End Using

        'Create a DataReader on alternate database
        Using myDr As IDataReader = Database.CreateDataReader("SELECT TOP 10 * FROM AccessUser", "Access.mdb")
            Do While myDr.Read
                Dim pageId As Integer = Input.FormatInteger(myDr.Item("AccessUserID"))
            Loop
        End Using

    End Sub

End Class
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

Database Class
Database Members
Overload List

Send Feedback