Solved

Adding many rows to a dataset

Posted on 2006-07-20
4
193 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
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 500 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

786 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