Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vb.net creating data table?

I'm using vb.net / winforms. How can I convert 10 lines with three columns into a DataSet/DataTable?

Lines are something like this:

Item-1, $100, 44

Item-2, $42, 3

etc
like image 236
Alex Avatar asked Mar 08 '11 23:03

Alex


1 Answers

Dim Table1 As DataTable
Table1 = New DataTable("TableName")

Dim column1 As DataColumn = New DataColumn("Column1")
column1.DataType = System.Type.GetType("System.String")

Dim column2 As DataColumn = New DataColumn("Column2")
column2.DataType = System.Type.GetType("System.Int32") 
Dim column3 As DataColumn = New DataColumn("Column2")
column3.DataType = System.Type.GetType("System.Int32")

Table1.Columns.Add(column1)
Table1.Columns.Add(column2)
Table1.Columns.Add(column3)


Dim Row1 As DataRow
Row1 = Table1.NewRow()

Row1.Items("Column1") = "Item1"
Row1.Items("Column2") = 44
Row1.Items("Column3") = 99

Table1.Rows.Add(Row1)

' Repeat for other rows
like image 64
Bala R Avatar answered Sep 24 '22 13:09

Bala R