Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6722201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:25:10+00:00 2026-05-26T09:25:10+00:00

I want to output some data to the user based on their username. This

  • 0

I want to output some data to the user based on their username. This data is held in a table that is linked to the aspnet_Users table. I’m trying to write a sqldatareader as part of a function so I don’t have to rewrite the code when it could be called from several pages. I know this is probably very simple buty I can’t seem to access the data from outside the function. The function I have so far is as follows:

Public Shared Function AgencyDetails() As SqlDataReader
    Dim details As String = "SELECT * FROM tbl_Relationships WHERE ContactSub = @Username"
    Dim connString As String = ConfigurationManager.ConnectionStrings("ApplicationServices").ConnectionString

    Using dbConnection As New SqlConnection(connString)
        dbConnection.Open()
        Dim cmdAgency As New SqlCommand(details, dbConnection)
        cmdAgency.Parameters.AddWithValue("@Username", membership.getuser)
        Return cmdAgency.ExecuteReader()


    End Using
End Function

How can I call this function and access the information on my page? Something like the following?

lblAgencyDetails.text = AgencyDetails(0)

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:25:10+00:00Added an answer on May 26, 2026 at 9:25 am

    The way you have it now, it won’t work because you enclosed the connection in a using statement, by the time you return the Reader the connection will be closed and disposed so the reader won’t be able to read anything.

    What you should do in that function is load the info in a DataTable and return the datatable.

    Example:

    Public Shared Function AgencyDetails() As DataTable
        Dim details As String = "SELECT * FROM tbl_Relationships WHERE ContactSub = @Username"
        Dim connString As String = ConfigurationManager.ConnectionStrings("ApplicationServices").ConnectionString
    
        Using dbConnection As New SqlConnection(connString)
            dbConnection.Open()
            Dim cmdAgency As New SqlCommand(details, dbConnection)
            cmdAgency.Parameters.AddWithValue("@Username", membership.getuser)
            Dim dt as new DataTable()
            dt.Load(cmdAgency.ExecuteReader())
            return dt
    
        End Using
    End Function
    

    You can access the rows in the data table by doing:

    For Each row as DataRow in dt.Rows
       Console.WriteLine(row("ColumnName"))
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got some data (the output of a ddply function) that I want to
to export some data i want to be able to generate an html output.
I want to generate some formatted output of data retrieved from an MS-Access database
I have a CSV file containing some user data it looks like this: 10333,,an.10,Kenyata,,Aaron,,,,,,,,,,
I want to output some characters in C# console application and then rewrite them,
i want to output some text in an label <input type=text size=20 maxlength=20 name=pizza1
I want to redirect the output of some Windows program directly to gvim basically
I want to write some debugging output to the log to review it with
when asp.net output a page ,I want to add some same parameters for all
I have a repeater control outputting some HTML. I want a table which outputs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.