Friday 15 January 2010

c# - Populate array with numbers from database -



c# - Populate array with numbers from database -

i'm trying figure out best way populate array numerical values pulled database. function have set far:

protected int[] getboxes() { int[] boxes; string query = "select distinct length products inner bring together baird_ground_boxes_products on uidbox = productid"; using (sqlconnection cn = new sqlconnection(ableconnectionstr)) { sqlcommand cmd = new sqlcommand(query, cn); cmd.commandtype = commandtype.text; cn.open(); using (idatareader reader = cmd.executereader()) { if (reader.read()) { if (reader["length"].tostring() !="") { //populate array length values returned } } } } homecoming boxes; }

there never single set of values returned (could 3, 2). i'm getting confused on how populate array, i'm making hard or something. suggestions helpful!

at first sight, may have multiple rows returned query.

select distinct length products bring together baird_ground_boxes_products on uidbox = productid

so, may read out of returned rows while loop.

var lengths = new list<string>(); if (reader.hasrows) while (reader.read()) lengths.add(reader.getstring(0)); homecoming lengths.toarray();

and wonder whether field length string. perhaps should consider using integer, since lengths expressed numbers. if so, wave getstring method in favour of getint32, , alter type of list.

var length = new list<int>(); lengths.add(reader.getint32(0));

c# arrays

No comments:

Post a Comment