---
title: "Generate DateRow for every row in a dataset"  
description: "Generate DateRow for every row in a dataset"  
author: "Jayden Bell"  
published: 2014-08-23  
updated: 2023-07-06  
canonical: https://www.mindstick.com/forum/2114/generate-daterow-for-every-row-in-a-dataset  
category: "vb.net"  
tags: ["vb.net"]  
reading_time: 2 minutes  

---

# Generate DateRow for every row in a dataset

```
Dim diaryreader As SqlDataReaderdiarycmd.CommandText = "dashboardusers"diarycmd.CommandType = CommandType.StoredProcedurediarycmd.Connection = usersconndiaryconn.Open()diaryreader = diarycmd.ExecuteReader() Dim diaryTable As DataTable = New DataTable()diaryTable.Load(diaryreader)Dim dr As DataRowfor each (dr in diaryTable.rows)
```

Next

This is not working, I [am getting](https://www.mindstick.com/forum/34179/i-am-getting-error-while-assigning-the-data-to-the-array-list) a [syntax error](https://www.mindstick.com/forum/159599/what-is-a-syntax-error-in-sql-give-an-example) when i try to do for each dr in diarytable.rows

## Replies

### Reply by Aryan Kumar

Sure, I can help you with that. Here is an example of how to generate a daterow in a dataset:

VB.Net

```plaintext
Imports System.Data

Sub Main()
    ' Create a new DataTable object.
    Dim dataTable As New DataTable("DateTable")

    ' Add a Date column to the DataTable object.
    dataTable.Columns.Add("Date", GetType(DateTime))

    ' Generate a daterow in the DataTable object.
    Dim daterow As DataRow = dataTable.NewRow()
    daterow("Date") = DateTime.Now

    ' Add the daterow to the DataTable object.
    dataTable.Rows.Add(daterow)

    ' Display the contents of the DataTable object.
    Dim rows As DataRowCollection = dataTable.Rows
    For Each row As DataRow In rows
        Console.WriteLine(row("Date"))
    Next
End Sub
```

This code will create a new DataTable object and add a Date column to it. The code will then generate a daterow in the DataTable object and add it to the DataTable object. Finally, the code will display the contents of the DataTable object on the console.

Here is an explanation of the code:

- The `DataTable` class represents a DataTable object.
- The `Columns` property of the `DataTable` class gets the collection of columns for the DataTable object.
- The `Add` method of the `Columns` property adds a column to the collection.
- The `NewRow` method of the `DataTable` class creates a new DataRow object.
- The `Date` property of the `DataRow` class sets the value of the Date column.
- The `Rows` property of the `DataTable` class gets the collection of rows for the DataTable object.
- The `Add` method of the `Rows` property adds a row to the collection.
- The `Console.WriteLine` method is used to print the contents of the DataTable object on the console.

### Reply by Sumit Kesarwani

Hi Jayden, \

You get errors because your braces are set wrong. This would work:

Dim dr As DataRow

For Each dr In diaryTable.Rows

Next


---

Original Source: https://www.mindstick.com/forum/2114/generate-daterow-for-every-row-in-a-dataset

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
