Add Rows to a Table

R

ruca

Hi,

I have this code:

--------------------------------------------
Dim myDataSet As DataSet
myDataSet = New DataSet("Funcionarios")
' Create two DataTable objects using a function.
Dim table As New DataTable()
Dim col as DataColumn
Dim data, dia, mes, ano as String
Dim horas as Date
Dim strValor as Date


'Adicionar três colunas
col = New DataColumn ("CdRcs", System.Type.GetType("System.String"))
table.Columns.Add(col)
col = New DataColumn ("Name", System.Type.GetType("System.String"))
table.Columns.Add(col)
col = New DataColumn ("Pwd", System.Type.GetType("System.String"))
table.Columns.Add(col)

myDataSet.Tables.Add(table)
Console.WriteLine(myDataSet.DataSetName, myDataSet.Tables.Count)
--------------------------------------------

Now I want to add some rows to myDataSet. How can I do that?
Example:
CdRsc = "001"
Name = "XPTO"
Pwd = "****"

CdRsc = "002"
Name = "OTPX"
Pwd = "****"

etc, etc...
NOTE: I don't have any DB associated, and it must be this way.


Thanks,
ruca
 
B

Brian Parlier

Dim row As DataRow = myDataSet.Tables(0).NewRow

row("CdRcs") = value
row("Name") = value
row("Pwd") = value

myDataSet.Tables(0).rows.add(row)

When you create the DataTable you could give it a name in the constructor
like Dim table As New DataTable("MyTable"). That way you can use that
rather than the index value of the Table.

Good luck,
Brian Parlier
 

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

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top