Solved

Adding many rows to a dataset

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

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: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

617 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