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

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -