Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default inserting new row in datatable

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default inserting new row in datatable

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


"joel" wrote:

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default inserting new row in datatable

On Aug 8, 7:56 pm, Vergel Adriano
wrote:
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



"joel" wrote:
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- Hide quoted text -


- Show quoted text -



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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CLosing Linked datatable Candyman Excel Programming 1 February 28th 07 03:57 PM
Chart's DataTable fujing1003 Charts and Charting in Excel 5 February 8th 07 11:20 AM
CHARTS DATATABLE GILBERT Excel Programming 3 September 29th 06 06:57 AM
how to delete row from the runtime Datatable sweta26_kum Excel Programming 0 July 18th 06 12:17 PM
DataTable number format MB Excel Programming 2 January 21st 05 07:11 PM


All times are GMT +1. The time now is 12:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"