c# 4.0 - Load some data from Sybase query reader using columns names -
i using sybase query reader can't find anyway far load data using column names instead of column number. know how to? here current reader i'd change:
var queryreader = thecontext.executestoredprocedure("dbo.sp_getmydata"); try { while (queryreader.read()) { if (queryreader.getvalue(0) == null) { continue; } int numdayspending; int.tryparse(queryreader.getvalue(2).tostring(), out numdayspending); ...
thank you!
i've found answer, needed generate dictionnary containing columns mappings [columnname;columnid]:
public dictionary<string, int> getcolumnsmap(asedatareader reader) { var columncount = reader.fieldcount; dictionary<string, int> columnsmap = new dictionary<string, int>(); (int columnid = 0; columnid < columncount; columnid++) { var columnname = reader.getname(columnid); if (!columnsmap.containskey(columnname)) { columnsmap.add(columnname, columnid); } } return columnsmap; }
usage:
brand = columnsmap["brands"]
Comments
Post a Comment