Hi, Folks.
I'm trying to use a list of lists to retrieve data from a query in a table.
The query is (simplified) "select C1, C2, C3 from Table1". So there are three columns and an unknown number of retrieved registries.
To deal with it I did:
I had to include an empty list (Temp) in TabValues so to receive the data.
After I run the command to get the registries in the table I did:
It didn't work. All lists inside TabValues receive the same values.
In this example I used 3 columns to recover, but I have to make my routine generic, with any number of columns.
Can anyone tell me what is wrong in may code? What is the best solution.
Thanks.
I'm trying to use a list of lists to retrieve data from a query in a table.
The query is (simplified) "select C1, C2, C3 from Table1". So there are three columns and an unknown number of retrieved registries.
To deal with it I did:
C#:
List<List<string>> TabValues();
List<string> Columns();
List<string> Resul();
List<string> Temp();
Columns.Add("C1");
Columns.Add("C2");
Columns.Add("C3");
TabValues.Add(Columns);
TabValues.Add(Temp);
TabValues.Add(Temp);
TabValues.Add(Temp);
After I run the command to get the registries in the table I did:
C#:
rdr = Cmd.ExecuteReader();
i=0;
while (rdr.Read())
{
for (j=0; j<3; j++)
{
TabValues.ElementAt(i+1).Insert(0, GetValue(j).ToString());
}
i++;
}
In this example I used 3 columns to recover, but I have to make my routine generic, with any number of columns.
Can anyone tell me what is wrong in may code? What is the best solution.
Thanks.
Last edited by a moderator: