sql server - C# - There is no row at position 0 -


this question has answer here:

i store result of request in list of character strings (list ) , store in dictionary (dictionary ) no matter request use, have error message : "there no row @ position 0".

public dictionary<string, object> getpicv2(string tdate_d, string ddl_fampic, string ddl_donnee, string ddl_detail, string ddl_caracteristique, string ddl_poste, string ddl_ilot, string ddl_nposte, string ddl_atelier, string ddl_tposte)     {         dictionary<string, object> list = new dictionary<string, object>();          sqldataadapter dac, dad, dam;         dataset dsm = new dataset();         dataset dsp = new dataset();         dataset dsd = new dataset();         dataset dsc = new dataset();         dataset dsb = new dataset();         datatable dtm = new datatable();         datatable dtc = new datatable();         datatable dtv = new datatable();         datatable dts = new datatable();         datatable dtp2 = new datatable();         datatable dtp3 = new datatable();           sqlconnection cn, cn1;         sqlcommand cmd1;         string sql = "", test = "";          cn = new sqlconnection(cs_pmi);         cn.open();          cn1 = new sqlconnection(cs_dw);         cn1.open();         sql = "";           // entête          // lecture des mois sur la période          sql = "select year(cakjdate),convert(varchar,datename( month , dateadd( month , month(cakjdate) , -1 ))),'01/'+substring(cakjdate,5,2)+'/'+substring(cakjdate,1,4),count(*)  ";         sql = sql + "from [pmi].[dbo].[calend] ";         sql = sql + "where caktsoc='100' , cakttype='01' , caktcode='' , cactactif='o' ";         sql = sql + "and cast(cakjdate datetime)>=convert(varchar,'" + tdate_d + "',103) , cast(cakjdate datetime)< convert(varchar,cast('" + tdate_d + "' datetime)+390,103) ";         sql = sql + "group convert(varchar,datename( month , dateadd( month , month([cakjdate]) , -1 ))),month([cakjdate]),year([cakjdate]),'01/'+substring(cakjdate,5,2)+'/'+substring(cakjdate,1,4) ";         sql = sql + "order year([cakjdate]),month([cakjdate]); ";           try         {             dam = new sqldataadapter(sql, cn);             dsm = new dataset();             dam.fill(dsm, "lstmois");             dtm = dsm.tables["lstmois"];              //lblerreur.text = dtm.rows[1][2].tostring();         }         catch (sqlexception e)         {              cn.close();             cn1.close();         }          // construction ligne entete du tableau         sql = "(select 'périodes' entite,'" + dtm.rows[0][0].tostring() + "<br>" + dtm.rows[0][1].tostring() + "' m01,'" + dtm.rows[1][0].tostring() + "<br>" + dtm.rows[1][1].tostring() + "' m02,'" + dtm.rows[2][0].tostring() + "<br>" + dtm.rows[2][1].tostring() + "' m03,'" + dtm.rows[3][0].tostring() + "<br>" + dtm.rows[3][1].tostring() + "' m04,'" + dtm.rows[4][0].tostring() + "<br>" + dtm.rows[4][1].tostring() + "' m05,'" + dtm.rows[5][0].tostring() + "<br>" + dtm.rows[5][1].tostring() + "' m06,'" + dtm.rows[6][0].tostring() + "<br>" + dtm.rows[6][1].tostring() + "' m07,'" + dtm.rows[7][0].tostring() + "<br>" + dtm.rows[7][1].tostring() + "' m08,'" + dtm.rows[8][0].tostring() + "<br>" + dtm.rows[8][1].tostring() + "' m09,'" + dtm.rows[9][0].tostring() + "<br>" + dtm.rows[9][1].tostring() + "' m10,'" + dtm.rows[10][0].tostring() + "<br>" + dtm.rows[10][1].tostring() + "' m11,'" + dtm.rows[11][0].tostring() + "<br>" + dtm.rows[11][1].tostring() + "' m12,'total' tt) ";          try         {             dad = new sqldataadapter(sql, cn);             //dsm = new dataset();             dad.fill(dsm, "entete");              list<string> listentete = new list<string>();              (int = 0; <= 13; i++)             {                 listentete.add(dsm.tables["entete"].rows[0][i].tostring());             }              list.add("entete", listentete);         }         catch (sqlexception e)         {              cn.close();             cn1.close();         } 

yet queries correct because use them in project.

thank in advance help

it's full code :

public dictionary<string, object> getpicv2(string tdate_d, string ddl_fampic, string ddl_donnee, string ddl_detail, string ddl_caracteristique, string ddl_poste, string ddl_ilot, string ddl_nposte, string ddl_atelier, string ddl_tposte)         {             dictionary<string, object> list = new dictionary<string, object>();              sqldataadapter dac, dad, dam;             dataset dsm = new dataset();             dataset dsp = new dataset();             dataset dsd = new dataset();             dataset dsc = new dataset();             dataset dsb = new dataset();             datatable dtm = new datatable();             datatable dtc = new datatable();             datatable dtv = new datatable();             datatable dts = new datatable();             datatable dtp2 = new datatable();             datatable dtp3 = new datatable();               sqlconnection cn, cn1;             sqlcommand cmd1;             string sql = "", test = "";              cn = new sqlconnection(cs_pmi);             cn.open();              cn1 = new sqlconnection(cs_dw);             cn1.open();             sql = "";               // entête              // lecture des mois sur la période              sql = "select year(cakjdate),convert(varchar,datename( month , dateadd( month , month(cakjdate) , -1 ))),'01/'+substring(cakjdate,5,2)+'/'+substring(cakjdate,1,4),count(*)  ";             sql = sql + "from [pmi].[dbo].[calend] ";             sql = sql + "where caktsoc='100' , cakttype='01' , caktcode='' , cactactif='o' ";             sql = sql + "and cast(cakjdate datetime)>=convert(varchar,'" + tdate_d + "',103) , cast(cakjdate datetime)< convert(varchar,cast('" + tdate_d + "' datetime)+390,103) ";             sql = sql + "group convert(varchar,datename( month , dateadd( month , month([cakjdate]) , -1 ))),month([cakjdate]),year([cakjdate]),'01/'+substring(cakjdate,5,2)+'/'+substring(cakjdate,1,4) ";             sql = sql + "order year([cakjdate]),month([cakjdate]); ";               try             {                 dam = new sqldataadapter(sql, cn);                 dsm = new dataset();                 dam.fill(dsm, "lstmois");                 dtm = dsm.tables["lstmois"];                  //lblerreur.text = dtm.rows[1][2].tostring();             }             catch (sqlexception e)             {                  cn.close();                 cn1.close();             }              // construction ligne entete du tableau             sql = "(select 'périodes' entite,'" + dtm.rows[0][0].tostring() + "<br>" + dtm.rows[0][1].tostring() + "' m01,'" + dtm.rows[1][0].tostring() + "<br>" + dtm.rows[1][1].tostring() + "' m02,'" + dtm.rows[2][0].tostring() + "<br>" + dtm.rows[2][1].tostring() + "' m03,'" + dtm.rows[3][0].tostring() + "<br>" + dtm.rows[3][1].tostring() + "' m04,'" + dtm.rows[4][0].tostring() + "<br>" + dtm.rows[4][1].tostring() + "' m05,'" + dtm.rows[5][0].tostring() + "<br>" + dtm.rows[5][1].tostring() + "' m06,'" + dtm.rows[6][0].tostring() + "<br>" + dtm.rows[6][1].tostring() + "' m07,'" + dtm.rows[7][0].tostring() + "<br>" + dtm.rows[7][1].tostring() + "' m08,'" + dtm.rows[8][0].tostring() + "<br>" + dtm.rows[8][1].tostring() + "' m09,'" + dtm.rows[9][0].tostring() + "<br>" + dtm.rows[9][1].tostring() + "' m10,'" + dtm.rows[10][0].tostring() + "<br>" + dtm.rows[10][1].tostring() + "' m11,'" + dtm.rows[11][0].tostring() + "<br>" + dtm.rows[11][1].tostring() + "' m12,'total' tt) ";              try             {                 dad = new sqldataadapter(sql, cn);                 //dsm = new dataset();                 dad.fill(dsm, "entete");                  list<string> listentete = new list<string>();                  (int = 0; <= 13; i++)                 {                     listentete.add(dsm.tables["entete"].rows[0][i].tostring());                 }                  list.add("entete", listentete);             }             catch (sqlexception e)             {                  cn.close();                 cn1.close();             } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -