Attention: We are retiring the ASP.NET Community Blogs. Learn more >

CreateDate - create a DataTable with some data in it...

I'm sick of writing this function so, I'll just park it here :-)

 

    Private Function CreateData() As DataTable
        Dim dt As New DataTable("TestData")
        Dim dc1 As New DataColumn("Id", GetType(Integer))
        Dim dc2 As New DataColumn("Name", GetType(String))
        Dim dc3 As New DataColumn("BirthDate", GetType(DateTime))
        dt.Columns.Add(dc1)
        dt.Columns.Add(dc2)
        dt.Columns.Add(dc3)
        Dim names() As String = {"darren", "peter", "robin", "phil", "wayne", "rob", "doug"}
        Dim theDate As DateTime = New DateTime(1968, 7, 22)
        For i As Integer = 0 To names.Length - 1
            Dim dr As DataRow = dt.NewRow
            dr("Id") = i
            dr("Name") = names(i)
            dr("BirthDate") = theDate
            dt.Rows.Add(dr)
        Next
    
        Return dt
    End Function

3 Comments

Comments have been disabled for this content.