Solved

Adding many rows to a dataset

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

896 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