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

  • Home
  • SEARCH
  • 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 9191861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:47:19+00:00 2026-06-17T20:47:19+00:00

DTName is a DataTable which returns rows in the code below…when I iterate it

  • 0

DTName is a DataTable which returns rows in the code below…when I iterate it through the loop from 0 to its count. Only the data in first row is displayed.

How to get all the rows of the datatable displayed in the result ?

DTName = GetClientNames()

   If Not DTName Is Nothing Then

      For i = 0 to DTName.Rows.count

         strName = DTName.Rows(i).Item("Client Name").Tostring()

      Next i

   End if
  • 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-17T20:47:21+00:00Added an answer on June 17, 2026 at 8:47 pm

    For i = 0 to DTName.Rows.count would eventually throw a IndexOutOfRangeException error when the value of i equals to DTName.Rows.count, the limit should be DTName.Rows.count - 1 .

    To get all the values from all datarows, store them in a List :

        Dim strName As New List(Of String)
    
        For i = 0 to DTName.Rows.count - 1
    
           strName.Add(DTName.Rows(i)("Client Name").Tostring())
    
        Next i
    

    Alternatively you could use Foreach like this :

        For Each DR As DataRow In DTName.Rows
    
           strName.Add(DR("Client Name").Tostring())
    
        Next
    

    I also suggest you remove the redundant check if DTName.Rows.Count > 0

    EDIT : You could Declare strName as string and append row values to it :

        For i = 0 to DTName.Rows.count - 1
    
            strName &= (DTName.Rows(i)("Client Name").Tostring() & ",")
    
        Next i
    
        Response.Write(strName)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I like to use parameter for FILENAME in the code below, instead of N'D:\DBName.mdf'
Below is my code to store images in the sqlite database. When I used
advertisers = db.dbname.find( 'my query which returns things correctly' ); I realize now that
I have DataTable containing necessary DataRows , which I want to display in ComboBox
I ran this query in my database : SELECT DB_NAME(dbid) as DBName, COUNT(dbid) as
Im using c# .net windows form application. I have created a database which has
For my database I create a new query and wrote select * from dbname
I have created a certificate basically straight from the keytool example page: keytool -genkey
I have the following code List<Department> depts = new List<Department>(); Department.Add(new Department() { DNo
I wrote the following code by serialization and a deserialization of forms and their

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.