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 8426115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:27:34+00:00 2026-06-10T04:27:34+00:00

I am simply trying to create an function to return a set of user.

  • 0

I am simply trying to create an function to return a set of user. But, in order to be able to add the item later to a collection I used arrayList, but at last I am getting an error of Type ArrayList cannot be converted to 1-Dimensional array of Users

Here is my Code:

Function getDoctorsList() As Users()
    Dim userCollection As New ArrayList
    Dim sql = "SELECT * FROM '" + _tblName + "' WHERE usertype = 'doctor'"
    Dim dr As SqlDataReader = dbHelper.ExecuteAndGetReader(sql)
    While dr.Read
        Dim user As New Users
        user.Id = IIf(IsDBNull(dr("id")), 0, dr("id"))
        user.UserName = IIf(IsDBNull(dr("username")), "", dr("username"))
        user.UserNin = IIf(IsDBNull(dr("user_nin")), 0, dr("user_nin"))
        user.UserType = IIf(IsDBNull(dr("usertype")), "", dr("usertype"))
        user.Password = IIf(IsDBNull(dr("password")), "", dr("password"))
        userCollection.Add(user)
    End While
    Return userCollection
End Function

How to solve such problems?

  • 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-06-10T04:27:35+00:00Added an answer on June 10, 2026 at 4:27 am

    Either let your method return an ArrayList:

    Function getDoctorsList() As ArrayList()
    

    create an Array out of your ArrayList:

    Return userCollection.ToArray()
    

    or, the best solution, let your method return an IEnumerable(Of User)

    Function getDoctorsList() As IEnumerable(Of User)
    

    you should also use a List(of User) instead of a ArrayList instead, since it is type safe (and clearer) and it also implements IEnumerable(Of User).


    Edit

    Example using IEnumerable(of Users) and DataRowExtensions:

    Function GetDoctorsList() As IEnumerable(of Users)
        Dim sql = "SELECT * FROM '" + _tblName + "' WHERE usertype = 'doctor'"
        Dim table = new DataTable()
        table.Load(dbHelper.ExecuteAndGetReader(sql))
        Return (from row in table.AsEnumerable()
                select new User() With
                {
                   .Id = row.FieldOf(Of Integer)("id"),
                   .UserName = row.Field(Of String)("username"),
                   .UserNin = row.Field(Of Integer)("user_nin"),
                   .UserType = row.Field(Of String)("usertype"),
                   .Password = row.Field(Of String)("password")
                }).ToList()
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a function that will simply allow me to pass an
I'm trying to create a simple Add-On for SQL Server 2008; it is simply
Update I'm trying to create a simple Go function which will simply take in
I'm trying to create a simple function which returns me a date with a
This is quite frustrating. I am simply trying to create a dynamic text and
I'm trying to create an app for Android that simply sends a command to
I am trying to create a very simple chat window that simply has the
what i'm trying to do this this. Simply create a C# windows app that
Im trying to create a simple pan and zoom app using silverlight 4, but
Im trying to create a simple input box with form validation, but im not

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.