inserting new row in datatable

J

joel

Hi
im new to vb.net i would like to know how to insert another row for my
datatable (like doing a for loop or something)...

in this code it only inserts a single row. help pls.

very much appreciated,

joel

Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSave.Click
Dim WarehouseDataTable As DataTable
WarehouseDataTable = New DataTable("Warehousing")

'creating a table named Customers
Dim Row1 As DataRow


'declaring three rows for the table

Try

Dim Department As DataColumn = New
DataColumn("Department")
'declaring a column named Name
Department.DataType = System.Type.GetType("System.String")
'setting the datatype for the column
WarehouseDataTable.Columns.Add(Department)
'adding the column to table

Dim SalesGLCode As DataColumn = New DataColumn("Sales GL
Code")
SalesGLCode.DataType =
System.Type.GetType("System.String")
WarehouseDataTable.Columns.Add(SalesGLCode)

Dim COSGLCode As DataColumn = New DataColumn("Cost Of
Sales")
COSGLCode.DataType = System.Type.GetType("System.String")
WarehouseDataTable.Columns.Add(COSGLCode)

Dim InventoryGLCode As DataColumn = New
DataColumn("Inventory")
InventoryGLCode.DataType =
System.Type.GetType("System.String")
WarehouseDataTable.Columns.Add(InventoryGLCode)

Dim ExpenseGLCode As DataColumn = New DataColumn("Expense
GL Code")
ExpenseGLCode.DataType =
System.Type.GetType("System.String")
WarehouseDataTable.Columns.Add(ExpenseGLCode)

Dim ReadersFeeGLCode As DataColumn = New
DataColumn("Reader's Fee GL Code")
ReadersFeeGLCode.DataType =
System.Type.GetType("System.String")
WarehouseDataTable.Columns.Add(ReadersFeeGLCode)

Row1 = WarehouseDataTable.NewRow
Row1.Item("Department") = Me.txtDepartment.Text
Row1.Item("Sales GL Code") = Me.txtSalesGLCode.Text
Row1.Item("Cost of Sales") = Me.txtCOSGLCode.Text
Row1.Item("Inventory") = Me.txtInventoryGLCode.Text
Row1.Item("Expense GL Code") = Me.txtExpenseGLCode.Text
Row1.Item("Reader's Fee GL Code") =
Me.txtReadersFeeGLCode.Text
WarehouseDataTable.Rows.Add(Row1)


Catch
End Try

Dim dsWarehouse As New DataSet
dsWarehouse = New DataSet
'creating a dataset

dsWarehouse.Tables.Add(WarehouseDataTable)
''adding the table to dataset

Var_Warehouse.SetDataBinding(dsWarehouse, "warehousing")
''binding the table to datagrid



End Sub
 
V

Vergel Adriano

You seem to have posted in the wrong group...but here's some code that
inserts 10 rows to a sample datatable to give you an idea.


Dim sampletable As DataTable = New DataTable("Sample")
Dim Row1 As DataRow
Dim Col1 As DataColumn = New DataColumn("col1")
Dim i As Integer

sampletable.Columns.Add(Col1)
For i = 1 To 10
Row1 = sampletable.NewRow
Row1("col1") = i
sampletable.Rows.Add(Row1)
Next
MsgBox(sampletable.Rows.Count)
 
J

joel

You seem to have posted in the wrong group...but here's some code that
inserts 10 rows to a sample datatable to give you an idea.

Dim sampletable As DataTable = New DataTable("Sample")
Dim Row1 As DataRow
Dim Col1 As DataColumn = New DataColumn("col1")
Dim i As Integer

sampletable.Columns.Add(Col1)
For i = 1 To 10
Row1 = sampletable.NewRow
Row1("col1") = i
sampletable.Rows.Add(Row1)
Next
MsgBox(sampletable.Rows.Count)

--
Hope that helps.

Vergel Adriano




















- Show quoted text -


Thanks Vergel. I'll try it out! sorry i posted it in the wrong group.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top