Solved

Adding many rows to a dataset

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now