Pass a database value to my array

  • Thread starter Thread starter de3a10
  • Start date Start date
D

de3a10

What Im trying to do is to get some int values from a column example
12345 in various records
so what i want is to create or insert them into my array to to identify
how many of each one of them are in the x column while(myReader.Read())
{
this is my column and I want to get all the numbers fro this columng
myReader["proCompra_cl"];. so far, this is what I have done.

// int numero0 = 0, numero1 = 0, numero2 = 0, numero3 = 0, numero4 =
0, numero5 = 0, numeroNull = 0;
// int[] myArray = new int [] {0,0,1,1,2,2,3,4,5};
//
// foreach (int i in myArray)
// {
// if (i == 0)
// numero0++;
// if (i == 1 )
// numero1++;
// if (i == 2)
// {
// numero2++;
// }
// if (i == 3)
// {
// numero3++;
// }
// if (i == 4)
// {
// numero4++;
// }
// if (i == 5)
// {
// numero5++;
// }
// else
// {
// numeroNull++;
// }
// }
// Response.Write("<br>");
// Response.Write(numero0+" iguales a 0,"+"<br>"+numero1+" iguales a
1"+"<br>"+numero2+" iguales a 2");


}
 
I think you could use SortedList (or Hashtable if you dont't want to
sort the table by key).

SortedList table = new SortedList();
int[] myArray = {3, 6, 7, 0, 1, 2, 2, 3};
// Populate the sort list
foreach (int i in myArray)
{
if (!table.ContainsKey(i))
{
table = 1;
}
else
{
table = (int) table + 1;
}
}

// Write to Response
foreach (DictionaryEntry e in table)
{
Console.WriteLine("<br>");
Console.WriteLine(String.Format("{0} iguales a {1}", e.Key,
e.Value));
}

Ragards,
Thi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top