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.
- [System.Web.Services.WebMethod]
- public static Dictionary< string, object> Load()
- {
- string sql = "SELECT Name,Marks FROM table4";
- using (SqlConnection Connection = newSqlConnection((@"myconnstrng")))
- {
- using (SqlCommand myCommand = new SqlCommand(sql,Connection))
- {
- Connection.Open();
- using (SqlDataReader myReader = myCommand.ExecuteReader())
- {
- DataTable dt = new DataTable();
- dt.Load(myReader);
- Connection.Close();
- var tableEnumerable = dt.AsEnumerable();
- var tableArray = tableEnumerable.ToArray();
- Dictionary<string, object> lst = new Dictionary<string, object>();
-
- return lst;
- }
- }
- }
- }