SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CommandBehavior is not declared.

    Can anyone see what Im doing wrong here

    Im simply trying to read all the records in a databse table then iterate through the returned records

    When running this page I get the error
    Name CommandBehavior is not declared

    My vb code is

    Imports System
    Imports System.Data.OleDB
    Imports System.Web.UI.WebControls
    Imports System.Web.UI

    Namespace JtaIntranet

    Public Class ViewAirlineBudget : Inherits Page
    Protected strMessage as String = "Airline Budget Report"

    Public Sub Page_Load(sender as object, e as EventArgs)
    'First set connection string to access database
    Dim strConn, databasePath as String
    databasePath = Server.MapPath("../datasource/EventBudgets.mdb")
    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& databasePath &";Mode=ReadWrite|Share Deny None;Persist Security Info=False"

    'Create connection to database and open it
    Dim objConnection as OleDbConnection
    objConnection = new OleDbConnection(strConn)
    objConnection.Open()

    'Specify SQL statement
    Dim strSQL as string = "SELECT * FROM tblAirLines"

    'Create the command object
    Dim objCommand as OleDbCommand
    objCommand = New OleDbCommand(strSQL, objConnection)

    'Set an OleDbDataReader to the commands results
    Dim objDataReader as OleDbDataReader
    objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)

    End Sub

    End Class
    End Namespace

  2. #2
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Add:

    Imports System.Data

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you dhtmlgod it does run now

    I am fairly new to ASP.NET and I thought the OleDbDataReader existed in
    Sytem.Data.OleDB which is where I got confused

    Thanks Again

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DataReader Namespace

    Hi All

    Can anyone tell me why when I try to create a OleDbDataReader the correct namspace to import seems to be

    Imports.System.Data

    and not

    Imports.System.Data.OleDb

    All the documentation I can find gives the System.Data.OleDb as the namespace to use but this did not seem to work until I used

    Imports.System.Data

    Many thanks

  5. #5
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,627
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    OleDbDataReader lives in System.Data.OleDb, but much of the ADO.NET implements a set of common functionality and behavior as they inherit from a set of classes and implement a set of interfaces found in System.Data and System.Data.Common.

    In your case, the CommandBehavior enumerations live in System.Data, which is why you were getting this error.

  6. #6
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OleDbDataReader is in the System.Data.OleDb namespace, your problem was related to the CommandBehaviour enum, which is port of System.Data.

  7. #7
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK thanks everyone for clearing that up


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •