0

I have a database that contain a table called ResourceInfo.

Inside ResourceInfo, there are 2 columns - resourcetype and description.

There is a global variable protected List<String> ResourceType = new List<String>(); that will actually and eventually get pass to the ASPX file's javascript.

The following is the C# code.

How do I store the data from the 2 columns into the variable ResourceType?

            if (caltab.HasRows)
            {
                while (caltab.Read())
                {
                    ArrayList txtval = (ArrayList)[caltab["resourcetype"], caltab["description"]];
                    ResourceType.Add(txtval);

                }
            }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jack
  • 1,603
  • 5
  • 25
  • 36
  • @ArsenMkrt The problem is that the ResourceType cannot add the arrayList `txtval`. The `txtval` is able to retrieve the database and the data in the 2 columns but `ResourceType` just cannot add the value of `txtval`. – Jack Nov 26 '12 at 10:12
  • I also change the code to `protected List ResourceType = new List();` but still could not get `ResourceType` to add the value of `txtval` – Jack Nov 26 '12 at 10:13
  • which version of .net are you using? can you use linq? – Arsen Mkrtchyan Nov 26 '12 at 10:15

1 Answers1

0

If you planning to use arraylist, the following code should work. Arraylist is a datastructure which can only store values and not key-value datatypes.

if (caltab.HasRows)
            {
                while (caltab.Read())
                {
                    ArrayList txtval = new ArrayList();
                    txtval.Add(caltab["resourcetype"]); txtval.Add(caltab["description"]);
                    ResourceType.Add(txtval);

                }
            }

Also, I would recommend using LINQ instead of ADO.NET. There are many reasons why LINQ is better What are the advantages of LINQ to SQL?

Community
  • 1
  • 1
Ashwin Singh
  • 7,197
  • 4
  • 36
  • 55