array or ?

  • Thread starter Thread starter Nikhil Patel
  • Start date Start date
N

Nikhil Patel

Hi all,
I need to read rows from DataReader. The rows have two columns FieldName
and FildeValue.
Below is a small sample data:

FieldName FieldValue
Company ABC Corp.
Company XYZ Corp.
Department Sales
Department IT
Deaprtment Accounting
....

In the application I will have two dropdowns - one for Company and one for
Department. I need to display the values read from DataReader into their
corresponding dropdown. Where should I store the data read from the
DataReader?
 
Nikhil,

Is this an ASP.NET page? If so, you can bind the list directly to the
data reader, and it will read the values from there.

If not, then you could use a data adapter and just have it stored in a
data table, and bind to that.

Hope this helps.
 
Hi Nikhil,

Create 2 DataView objects. Filter rows from DataReader into each one of
the dataview objects based on the FieldName [Company / Department]. Now,
bind the dataview to your dropdowns.

HTH,
-Azhagan
 
DataReader dr = new DataReader(.....);
DropDownList ddlCompany = new DropDownList()
DropDownList ddlDepartment = new DropDownList()
// :
// :
while (dr.Read())
{
string Fieldname = dr.GetString(0);
string FieldValue = dr.GetString(1);

switch (FieldName)
{
case "Company":
ddlCompany.Items.Add(FieldValue);
break;

case "Department":
ddlDepartment.Items.Add(FieldValue);
break;
}

}


--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
 
Back
Top