How do I count rows in a dataset or loop through a column?

I want to assign a dataset row count to an integer type variable. This is what I did, but it's not working:

countcourses = dataset.Tables("Course").Rows.Count

Also, how do I loop through a dataset column and extract every value to a collection of strings (or in my case, a class that holds the string collection)

Thanks for any help.


Answer this question

How do I count rows in a dataset or loop through a column?

  • knikki98

    Thanks a million. that was all the help I needed..and more!

  • Catalin Zima

    to loop through a dataset and columns:

    for each currentRow as DataRow in theDataSet.Tables(0).Rows

    for each currentColumn as DataColumn in currentRow

    MessageBox.Show(currentRow(currentColumn.ColumnName).ToString())

    next

    next

    this will loop through each row and each column in that row and show you the result. The DataRow collection is the array that holds the rows and column values:

    theDataSet.Tables(0).Rows(index)(ColumnNameOrIndex).ToString()

    now in your first question, not sure I follow what you mean by you want to assign a dataset row count to an integer type variable firstly you cant assign the row count value and secondly the count value is an integer type



  • How do I count rows in a dataset or loop through a column?