Simple Datatable Question

G

Guest

Can someone please tell me how I add information to a datatable!

I already have some information that has been pulled from an Active
Directory Database but I want to add additional information from an SQL
Server Database...

How do I achieve this???

Thanks

Private Sub createTable()
Dim tbcontacts As DataTable = New DataTable("contacts")
tbcontacts.Columns.Add(" ", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Name", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Dept.", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Ext", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Email", System.Type.GetType("System.String"))
ds.Tables.Add(tbcontacts)

End Sub
 
G

Guest

You want to add DataRows in DataTable which is created in your sample code?

I have always added rows like this (C#)

tbcontacts.Rows.Add(new object[]{[column 1 value], [column 2
value],...[column n value]})
 
G

Guest

Thanks... but not exactly what I wanted to know!

I have a database and usually use a data reader to access info from a
database but I want to add aditional info to an existing datatable...

Any ideas???

Jouni Karppinen said:
You want to add DataRows in DataTable which is created in your sample code?

I have always added rows like this (C#)

tbcontacts.Rows.Add(new object[]{[column 1 value], [column 2
value],...[column n value]})









Tim::.. said:
Can someone please tell me how I add information to a datatable!

I already have some information that has been pulled from an Active
Directory Database but I want to add additional information from an SQL
Server Database...

How do I achieve this???

Thanks

Private Sub createTable()
Dim tbcontacts As DataTable = New DataTable("contacts")
tbcontacts.Columns.Add(" ", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Name", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Dept.", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Ext", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Email", System.Type.GetType("System.String"))
ds.Tables.Add(tbcontacts)

End Sub
 
K

Karl Seguin

Why not just pull the data from the database into a 2nd datable, and then
copy all the rows from this new datatable to the tbContacts one?

you can do this something like:
for i as integer = 0 to databaseTable.Rows.Count - 1
tbContacts.Rows.Add(databaseTable.Rows(i).ItemArray)
next

Karl
 

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