What am i doing wrong in this dataset?

S

Shapper

Hello,

I am trying to create a dataset by adding rows to it in a For loop:

Dim dsNews As DataSet = New DataSet()
Dim row As DataRow = dsNews.Tables(0).NewRow()

dsNews.Tables.Add
dsNews.Tables(0).Columns.Add("title", GetType(String))
dsNews.Tables(0).Columns.Add("description", GetType(String))

For x = 1 To 10

With row
.Item("title") = "Some Title"
.Item("description") = "Some Description"
End With

dsNews.Tables(0).Add(row)

Next x

I get the error:
'Add' is not a member of 'System.Data.DataTable'.

What am I doing wrong?

Thanks,
Miguel
 
P

Paul Wu

Miguel:

DataTable does not have an "Add" method. You have to "Add" to the DataRowCollection of DataTable. You will also need to create "NewRow" inside your loop. See the following code snippet for an example:

Dim Table As New DataTable
Dim Count As Integer
Dim NewRow As DataRow
For Count = 1 To 10
NewRow = Table.NewRow
NewRow.Item("Title") = "Some Title" & Count.ToString
NewRow.Item("Description") = "Some Description" & Count.ToString
Table.Rows.Add(NewRow)
Next


Hope this helps,

Paul Wu
www.rulemasters.com
 

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,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top