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;
- }
- }
- }
- }

Dilip GuptaRank #2,085 · 690 reputationPosted Dec 26, 2016, 12:13 AM EST
sudipta sanyalRank #1,945 · 753 reputationPosted Dec 26, 2016, 12:18 AM EST
sudipta sanyalRank #1,945 · 753 reputationPosted Dec 26, 2016, 12:54 AM EST
Dinesh SanthalingamRank #2,085 · 690 reputationPosted Dec 26, 2016, 12:37 AM EST
Dinesh SanthalingamRank #2,085 · 690 reputationPosted Dec 26, 2016, 1:03 AM EST
Midhun TpRank #388 · 6.5K reputationPosted Dec 26, 2016, 1:04 AM EST
sudipta sanyalRank #1,945 · 753 reputationPosted Dec 26, 2016, 1:08 AM EST
Dinesh SanthalingamRank #2,085 · 690 reputationPosted Dec 26, 2016, 1:51 AM EST
Midhun TpRank #388 · 6.5K reputationPosted Dec 26, 2016, 1:56 AM EST
Dinesh SanthalingamRank #2,085 · 690 reputationPosted Dec 26, 2016, 2:02 AM EST
Dinesh SanthalingamRank #2,085 · 690 reputationPosted Dec 26, 2016, 2:39 AM EST
MayankRank #4,018 · 371 reputationPosted Dec 26, 2016, 3:04 AM EST
{
// tableArray[1].ItemArray[1]
lst.Add(data.ItemArray[1].ToString(), new { Id = data.ItemArray[0].ToString(), Name = data.ItemArray[1].ToString() });
}
Dinesh SanthalingamRank #2,085 · 690 reputationPosted Dec 26, 2016, 3:19 AM EST