Professional Web Applications Themes

issues with database class - ASP.NET General

Hello, I am having issues returning the results from the database using a data access class. The class is called dbconnect.vb. Imports System Imports System.Data Imports System.Data.SqlClient Namespace articles Public Class DBConnect Public Shared Function GetReader(ByVal p_storProc As String) As SqlDataReader Dim errorMessage As String Dim connection = New SqlConnection(DbUrl) Try connection.Open() Dim command = New SqlCommand() command.Connection = connection command.CommandText = p_storProc command.CommandType = CommandType.StoredProcedure Dim dataReader = command.ExecuteReader (CommandBehavior.CloseConnection) Return dataReader Catch e As Exception errorMessage = e.ToString() Finally connection.Close() End Try End Function Public Shared ReadOnly Property DbUrl() As String Get Return ConfigurationSettings.AppSettings("DbConnUrl") End Get End Property ...

  1. #1

    Default issues with database class

    Hello,

    I am having issues returning the results from the database using a data
    access class. The class is called dbconnect.vb.

    Imports System
    Imports System.Data
    Imports System.Data.SqlClient


    Namespace articles

    Public Class DBConnect
    Public Shared Function GetReader(ByVal p_storProc As String) As
    SqlDataReader

    Dim errorMessage As String
    Dim connection = New SqlConnection(DbUrl)

    Try
    connection.Open()

    Dim command = New SqlCommand()
    command.Connection = connection
    command.CommandText = p_storProc
    command.CommandType = CommandType.StoredProcedure

    Dim dataReader = command.ExecuteReader
    (CommandBehavior.CloseConnection)
    Return dataReader

    Catch e As Exception

    errorMessage = e.ToString()

    Finally
    connection.Close()

    End Try

    End Function


    Public Shared ReadOnly Property DbUrl() As String
    Get
    Return ConfigurationSettings.AppSettings("DbConnUrl")
    End Get
    End Property

    End Namespace



    I'm not getting any errors but the recordset is not being returned to the
    page.

    In a separate class file, mbl_plus.vb I am making an instance of the
    dbconnect class and filling a data reader.

    Both classes reside in a project called articles.

    here is mlb_plus.vb

    Imports System
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Data
    Imports System.Data.SqlClient
    Imports articles
    Imports System.Configuration
    Imports System.Text.RegularExpressions


    Public Class DisplayMLBPlus : Inherits UserControl
    Private gdID1 As String
    Private gdTitle1 As String
    Private gdAuthor1 As String

    Private gdID2 As String
    Private gdTitle2 As String
    Private gdAuthor2 As String

    Private gdID3 As String
    Private gdTitle3 As String
    Private gdAuthor3 As String


    Public ReadOnly Property ID1() As String
    Get
    Return gdID1
    End Get
    End Property

    Public ReadOnly Property title1() As String
    Get
    Return gdTitle1
    End Get
    End Property

    Public ReadOnly Property author1() As String
    Get
    Return gdAuthor1
    End Get
    End Property


    Public ReadOnly Property ID2() As String
    Get
    Return gdID2
    End Get
    End Property

    Public ReadOnly Property title2() As String
    Get
    Return gdTitle2
    End Get
    End Property

    Public ReadOnly Property author2() As String
    Get
    Return gdAuthor2
    End Get
    End Property

    Public ReadOnly Property ID3() As String
    Get
    Return gdID3
    End Get
    End Property

    Public ReadOnly Property title3() As String
    Get
    Return gdTitle3
    End Get
    End Property

    Public ReadOnly Property author3() As String
    Get
    Return gdAuthor3
    End Get
    End Property

    Sub Page_Load()
    If Not Page.IsPostBack Then

    Dim newConn As DBConnect = New DBConnect()
    Dim dtrGameday As SqlDataReader

    Try
    dtrGameday = newConn.GetReader("getMLBPlus")

    Dim cc As Integer
    cc = 0

    Do While dtrGameday.Read()

    Dim theID As String
    Dim theTitle As String
    Dim theAuthor As String

    If cc = 0 Then
    theID = dtrGameday("art_id")
    gdID1 = theID

    theTitle = dtrGameday("art_title")
    gdTitle1 = theTitle

    theAuthor = dtrGameday("art_author")
    gdAuthor1 = theAuthor
    ElseIf cc = 1 Then
    theID = dtrGameday("art_id")
    gdID2 = theID

    theTitle = dtrGameday("art_title")
    gdTitle2 = theTitle

    theAuthor = dtrGameday("art_author")
    gdAuthor2 = theAuthor
    ElseIf cc = 2 Then
    theID = dtrGameday("art_id")
    gdID3 = theID

    theTitle = dtrGameday("art_title")
    gdTitle3 = theTitle

    theAuthor = dtrGameday("art_author")
    gdAuthor3 = theAuthor
    End If

    cc = cc + 1
    Loop

    Catch e As Exception
    Dim errorMessage As String
    errorMessage = e.ToString()
    dtrGameday.Close()
    Finally
    dtrGameday.Close()
    End Try


    End If

    End Sub


    End Class


    I've tested the stored procedure in yzer and the results are
    returned. I've also moved the connection code out of the DBConnect class
    and into the mlb_plus class and it worked as well. I'm quite confused by
    this. I've added the dll reference to the project so I'm not sure what
    the issue could be. Any help would be much appreciated. Thanks...Scott
    Scott Collens Guest

  2. #2

    Default Re: issues with database class

    search for "Application Blocks" on microsoft.com. Then download the Data
    Access Application Blocks for .NET.

    It's an excellent, prewritten, pretested data access class by Microsoft,
    available in both vb.net and c#. I use it on all my projects. Never write
    data access code again!


    "Scott Collens" <scottcollensnospam.hotmail.com> wrote in message
    news:Xns93D0BC223498Bscottcollensnospamho207.46.2 48.16...
    > Hello,
    >
    > I am having issues returning the results from the database using a data
    > access class. The class is called dbconnect.vb.
    >
    > Imports System
    > Imports System.Data
    > Imports System.Data.SqlClient
    >
    >
    > Namespace articles
    >
    > Public Class DBConnect
    > Public Shared Function GetReader(ByVal p_storProc As String) As
    > SqlDataReader
    >
    > Dim errorMessage As String
    > Dim connection = New SqlConnection(DbUrl)
    >
    > Try
    > connection.Open()
    >
    > Dim command = New SqlCommand()
    > command.Connection = connection
    > command.CommandText = p_storProc
    > command.CommandType = CommandType.StoredProcedure
    >
    > Dim dataReader = command.ExecuteReader
    > (CommandBehavior.CloseConnection)
    > Return dataReader
    >
    > Catch e As Exception
    >
    > errorMessage = e.ToString()
    >
    > Finally
    > connection.Close()
    >
    > End Try
    >
    > End Function
    >
    >
    > Public Shared ReadOnly Property DbUrl() As String
    > Get
    > Return ConfigurationSettings.AppSettings("DbConnUrl")
    > End Get
    > End Property
    >
    > End Namespace
    >
    >
    >
    > I'm not getting any errors but the recordset is not being returned to the
    > page.
    >
    > In a separate class file, mbl_plus.vb I am making an instance of the
    > dbconnect class and filling a data reader.
    >
    > Both classes reside in a project called articles.
    >
    > here is mlb_plus.vb
    >
    > Imports System
    > Imports System.Web.UI
    > Imports System.Web.UI.WebControls
    > Imports System.Data
    > Imports System.Data.SqlClient
    > Imports articles
    > Imports System.Configuration
    > Imports System.Text.RegularExpressions
    >
    >
    > Public Class DisplayMLBPlus : Inherits UserControl
    > Private gdID1 As String
    > Private gdTitle1 As String
    > Private gdAuthor1 As String
    >
    > Private gdID2 As String
    > Private gdTitle2 As String
    > Private gdAuthor2 As String
    >
    > Private gdID3 As String
    > Private gdTitle3 As String
    > Private gdAuthor3 As String
    >
    >
    > Public ReadOnly Property ID1() As String
    > Get
    > Return gdID1
    > End Get
    > End Property
    >
    > Public ReadOnly Property title1() As String
    > Get
    > Return gdTitle1
    > End Get
    > End Property
    >
    > Public ReadOnly Property author1() As String
    > Get
    > Return gdAuthor1
    > End Get
    > End Property
    >
    >
    > Public ReadOnly Property ID2() As String
    > Get
    > Return gdID2
    > End Get
    > End Property
    >
    > Public ReadOnly Property title2() As String
    > Get
    > Return gdTitle2
    > End Get
    > End Property
    >
    > Public ReadOnly Property author2() As String
    > Get
    > Return gdAuthor2
    > End Get
    > End Property
    >
    > Public ReadOnly Property ID3() As String
    > Get
    > Return gdID3
    > End Get
    > End Property
    >
    > Public ReadOnly Property title3() As String
    > Get
    > Return gdTitle3
    > End Get
    > End Property
    >
    > Public ReadOnly Property author3() As String
    > Get
    > Return gdAuthor3
    > End Get
    > End Property
    >
    > Sub Page_Load()
    > If Not Page.IsPostBack Then
    >
    > Dim newConn As DBConnect = New DBConnect()
    > Dim dtrGameday As SqlDataReader
    >
    > Try
    > dtrGameday = newConn.GetReader("getMLBPlus")
    >
    > Dim cc As Integer
    > cc = 0
    >
    > Do While dtrGameday.Read()
    >
    > Dim theID As String
    > Dim theTitle As String
    > Dim theAuthor As String
    >
    > If cc = 0 Then
    > theID = dtrGameday("art_id")
    > gdID1 = theID
    >
    > theTitle = dtrGameday("art_title")
    > gdTitle1 = theTitle
    >
    > theAuthor = dtrGameday("art_author")
    > gdAuthor1 = theAuthor
    > ElseIf cc = 1 Then
    > theID = dtrGameday("art_id")
    > gdID2 = theID
    >
    > theTitle = dtrGameday("art_title")
    > gdTitle2 = theTitle
    >
    > theAuthor = dtrGameday("art_author")
    > gdAuthor2 = theAuthor
    > ElseIf cc = 2 Then
    > theID = dtrGameday("art_id")
    > gdID3 = theID
    >
    > theTitle = dtrGameday("art_title")
    > gdTitle3 = theTitle
    >
    > theAuthor = dtrGameday("art_author")
    > gdAuthor3 = theAuthor
    > End If
    >
    > cc = cc + 1
    > Loop
    >
    > Catch e As Exception
    > Dim errorMessage As String
    > errorMessage = e.ToString()
    > dtrGameday.Close()
    > Finally
    > dtrGameday.Close()
    > End Try
    >
    >
    > End If
    >
    > End Sub
    >
    >
    > End Class
    >
    >
    > I've tested the stored procedure in yzer and the results are
    > returned. I've also moved the connection code out of the DBConnect class
    > and into the mlb_plus class and it worked as well. I'm quite confused by
    > this. I've added the dll reference to the project so I'm not sure what
    > the issue could be. Any help would be much appreciated. Thanks...Scott

    George Durzi Guest

Similar Threads

  1. Solved connect database to gri ypusing class
    By manij s sherje in forum Brainstorming Area
    Replies: 0
    Last Post: March 3rd, 09:32 AM
  2. #39317 [NEW]: Fatal error: Database class not found
    By ldwebtech at yahoo dot com in forum PHP Bugs
    Replies: 1
    Last Post: October 31st, 11:31 AM
  3. Database connection issues
    By bronzeville in forum Dreamweaver AppDev
    Replies: 1
    Last Post: March 30th, 01:55 PM
  4. Flash MX Object/Class Issues???
    By jbuckle25 in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: February 13th, 08:18 PM
  5. Database Security Issues
    By Jonathan Lamothe in forum PHP Development
    Replies: 14
    Last Post: December 1st, 12:26 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139