473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

What am i doing wrong in this dataset?

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

Nov 19 '05 #1
1 1090
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
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message news:uI**************@TK2MSFTNGP14.phx.gbl...
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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

52
by: Tony Marston | last post by:
Several months ago I started a thread with the title "What is/is not considered to be good OO programming" which started a long and interesting discussion. I have condensed the arguments into a...
2
by: vbMark | last post by:
When I call the below code what I get returned is the string "System.Data.DataRow" I don't understand how this works. What am I doing wrong? private string GetData(string strQuery) {...
2
by: Aaron Ackerman | last post by:
I cannot a row to this bound DataGrid to SAVE MY LIFE! I have tried everything and I am at a loss. The using goes into add mode with the add button adds his data then updates with the update...
3
by: J | last post by:
Hi, I've a problem with a page I've developed, and I can't see where I'm going wrong. I've created a dataset called "Recipients", and in this dataset, I've created two tables, one called...
1
by: Miguel Dias Moura | last post by:
Hello, i have an ASP.net / VB page which i want to display 1 record of a database acording to this: 1. The page receives a variable name "Explicador" in the URL. Example: "Explicador = Jonh...
8
by: cjobes | last post by:
Hi all, The code below is part of a form where I would like the user to make selections from a table. The data is brought into the form from another form with: Public WriteOnly Property...
12
by: Gary Paris | last post by:
I have enclosed the sample code that I created. I want to read in employee data, and modify a few fields. I have tried to globally declare the objects that I need but I still am having problems. ...
16
by: SLIMSHIM | last post by:
Hi, I"m new to c# and .net. I wrote a small program to add rows to an access table. the program goes thru the motions but the data never gets there. here is my code. I am intentionaly not using...
0
by: CheshireCat | last post by:
I have added an access database into my 2005 desktop project, created a dataset called ResourcesDataSet which contains one of each table in the database using the wizard. The database was...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.