Dinesh Santhalingam

Dinesh Santhalingam

  • NA
  • 737
  • 368.5k

load data table to array

Dec 26 2016 4:56 AM
I have a sql table .I want load my table content into a data table dt .Add my data table content into an array and my array(tablearray) into a dictionary (lst).At last i return my dictionary .Here my code .I don't know How to add my array into dictionary? please help me to solve this problem.
    1. [System.Web.Services.WebMethod]  
    2. public static  Dictionary< string, object> Load()    
    3.   {    
    4.           string sql = "SELECT Name,Marks FROM table4";    
    5.   using (SqlConnection Connection = newSqlConnection((@"myconnstrng")))    
    6.           {    
    7.  using (SqlCommand myCommand = new SqlCommand(sql,Connection))    
    8.               {    
    9.                   Connection.Open();    
    10.          using (SqlDataReader myReader = myCommand.ExecuteReader())    
    11.                   {    
    12.                       DataTable dt = new DataTable();    
    13.                       dt.Load(myReader);    
    14.                       Connection.Close();    
    15.                       var tableEnumerable = dt.AsEnumerable();    
    16.                       var tableArray = tableEnumerable.ToArray();    
    17.         Dictionary<string, object> lst = new Dictionary<string, object>();    
    18.                          
    19.                     return lst;    
    20.                      }    
    21.                 }    
    22.              }    
    23.   }
 

Answers (13)