Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Asp.net是否具有arraylist以接收SQL Server的两列或多列数据?_C#_Asp.net_Sql Server 2008_Multidimensional Array - Fatal编程技术网

C#Asp.net是否具有arraylist以接收SQL Server的两列或多列数据?

C#Asp.net是否具有arraylist以接收SQL Server的两列或多列数据?,c#,asp.net,sql-server-2008,multidimensional-array,C#,Asp.net,Sql Server 2008,Multidimensional Array,我有一个数据库,其中包含一个名为ResourceInfo的表 在ResourceInfo中,有两列-resourcetype和description 存在一个全局变量protected List ResourceType=new List()这将实际并最终传递到ASPX文件的javascript 下面是C代码 如何将这两列中的数据存储到变量ResourceType if (caltab.HasRows) { whil

我有一个数据库,其中包含一个名为
ResourceInfo
的表

ResourceInfo
中,有两列-
resourcetype
description

存在一个全局变量
protected List ResourceType=new List()这将实际并最终传递到ASPX文件的javascript

下面是C代码

如何将这两列中的数据存储到变量
ResourceType

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

                }
            }

如果您计划使用arraylist,以下代码应该可以工作。Arraylist是一种数据结构,它只能存储值而不能存储键值数据类型

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

                }
            }

另外,我建议使用LINQ而不是ADO.NET。LINQ更好的原因有很多

@ArsenMkrt问题是ResourceType无法添加arrayList
txtval
txtval
能够检索数据库和两列中的数据,但是
ResourceType
无法添加
txtval
的值。我还将代码更改为
protected List ResourceType=new List()
但仍然无法获取
ResourceType
以添加
txtval
的值。您正在使用哪个版本的.net?你会用linq吗?