?
Solved

ListVitem to dataset in C#

Posted on 2009-04-23
7
Medium Priority
?
271 Views
Last Modified: 2012-05-06
I am in the process of convert a vb.net program over to C#. I am getting hung up on moving a listview over to a dataset and then to a simple xml file. I am not that experienced in C# so please keep it simple.
DataSet ds = this.Tickets;
                foreach (ListViewItem item in ListView1.Items)
                {
                    object[] data = new object[item.SubItems.Count];
                    for (int x = 0; x <= item.SubItems.Count - 1; x++)
                    {
                        data(x) = item.SubItems(x).Text;
                    }
                    ds.Tables("Ticket").LoadDataRow(data, true);
                }
                ds.WriteXml("\\\\vwmidsv01\\Shares\\TN Programs\\AgeOven\\data\\Tickets.xml");

Open in new window

0
Comment
Question by:fuzzymallets1
  • 5
7 Comments
 
LVL 30

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 1000 total points
ID: 24220500
Is the above code working? What's not working?

Do you have VB version code that works?
0
 
LVL 5

Assisted Solution

by:rendaduiyan
rendaduiyan earned 1000 total points
ID: 24222408
are all fields in Tickets are string type?
is any column not null?
anyway, make sure the data is valid.
0
 
LVL 5

Author Comment

by:fuzzymallets1
ID: 24224280
This is my vb code converted to C#. It works in vb. When I converted it over the data(x) say its a var but used like a method and the SubItems(x) and Tables("Tickets") says Non-Invocable member cannot be uses as a method

DataSet ds = this.Tickets;
                foreach (ListViewItem item in ListView1.Items)
                {
                    object[] data = new object[item.SubItems.Count];
                    for (int x = 0; x <= item.SubItems.Count - 1; x++)
                    {
                        data(x) = item.SubItems(x).Text;   /* data -- var but used as method, Subitem Non-Invocable member  /*
                    }
                    ds.Tables("Ticket").LoadDataRow(data, true);  /*Table --  Non-Invocable member cannot be uses as a method /*
                }

This shows you all my lacking of C# experience.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 5

Author Comment

by:fuzzymallets1
ID: 24224345
Also, all the data types in the dataset are strings.
0
 
LVL 5

Author Comment

by:fuzzymallets1
ID: 24224392
Here is the vb version of the code I converted



Dim ds As DataSet = Me.Tickets
            For Each item As ListViewItem In ListView1.Items
                Dim data(item.SubItems.Count - 1) As Object
                For x As Integer = 0 To item.SubItems.Count - 1
                    data(x) = item.SubItems(x).Text
                Next
                ds.Tables("Ticket").LoadDataRow(data, True)
            Next
            ds.WriteXml("\\vwmidsv01\Shares\TN Programs\AgeOven\data\Tickets.xml")

Open in new window

0
 
LVL 5

Author Comment

by:fuzzymallets1
ID: 24227615
Like I said my C# skill are lacking but I figure out the problem.

for (int x = 0; x <= item.SubItems.Count - 1; x++)

Should have been

for (int x = 0; x < item.SubItems.Count; x++)

0
 
LVL 5

Accepted Solution

by:
fuzzymallets1 earned 0 total points
ID: 24227629
Here is what I ended up doing.

DataSet ds = this.Tickets;
                foreach (ListViewItem item in ListView1.Items)
                {
                    object[] data = new object[item.SubItems.Count];
                    for (int x = 0; x < item.SubItems.Count; x++)
                    {
                        data[x] = item.SubItems[x].Text;
                    }
                    ds.Tables["Ticket"].LoadDataRow(data, true);
                }
                ds.WriteXml("\\\\vwmidsv01\\Shares\\TN Programs\\AgeOven\\data\\Tickets.xml");

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

829 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