Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Adding many rows to a dataset

Posted on 2006-07-20
4
Medium Priority
?
201 Views
Last Modified: 2010-04-23
Experts

I am a dataset newb do not usually use them, but need to on this occasion.  I have an array assigned as 50, within this array i have a structrue of 3 fields, fax , ref and name. So for example row 0 in the array would hold:

fax = 12321321
ref = an
name = a name

This is repeated many times with differing values.  What I wish to be able to do is add these values to a dataset, can save 1 row to a dataset but not any more.

 Dim ds As New DataSet()
        Dim dtList As New DataTable("List")
        Dim dr As DataRow = dtList.NewRow()


        dtList.Columns.Add("fax", GetType(Int64))
        dtList.Columns.Add("ref", GetType(String))
        dtList.Columns.Add("name", GetType(String))


    dr("fax") = (data_temp(ctl).fax)
            dr("ref") = (data_temp(ctl).ref)
            dr("name") = (data_temp(ctl).name)
            dtList.Rows.Add(dr)
            ctl = ctl + 1

  ds.Tables.Add(dtList)

But not sure how to add many rows. Probably missing something simple.

Any help appreciated.

Regards

Chas

 
0
Comment
Question by:chas805
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 6

Expert Comment

by:Nandakumar Sakthivel
ID: 17145555

Try like this

        Dim ds As New DataSet()
        Dim dtList As New DataTable("List")
        Dim dr As DataRow
       
        dtList.Columns.Add("fax", GetType(Int64))
        dtList.Columns.Add("ref", GetType(String))
        dtList.Columns.Add("name", GetType(String))

-------->start your loop here

            dr = dtList.NewRow()
            dr("fax") = (data_temp(ctl).fax)
            dr("ref") = (data_temp(ctl).ref)
            dr("name") = (data_temp(ctl).name)
            dtList.Rows.Add(dr)
            ctl = ctl + 1

--------->ends here
     
  ds.Tables.Add(dtList)

Thanks,
Nanda
0
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 2000 total points
ID: 17145557
You were on the right track....you just have to loop.

Dim ds As New DataSet
        Dim dtList As New DataTable("List")
        Dim dr As DataRow

        dtList.Columns.Add("fax", GetType(Int64))
        dtList.Columns.Add("ref", GetType(String))
        dtList.Columns.Add("name", GetType(String))

        For ctl = 0 To data_temp.Length - 1
            dr = dtList.NewRow
            dr("fax") = (data_temp(ctl).fax)
            dr("ref") = (data_temp(ctl).ref)
            dr("name") = (data_temp(ctl).name)
            dtList.Rows.Add(dr)
        Next

        ds.Tables.Add(dtList)
0
 
LVL 34

Expert Comment

by:Sancler
ID: 17145698
SNAP ;-)

Just a question - not for points.

Why, if you are just using one table, do you need a dataset?

Roger
0
 

Author Comment

by:chas805
ID: 17145795
thanks all

SNAP need to bind the ds to a grid like this -  fg.SetDataBinding(ds, logicString, True)

this only way i know of doing this, think it is right.

Regards

chas
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question