SQL Command Result to Dictionary C# .NET 2.0

后端 未结 5 641
感动是毒
感动是毒 2021-02-01 06:55

I have a simple SQL query (using SqlCommand, SqlTransaction) in .NET 2.0 that returns a table of integer-string pairs (ID, Name). I want to get this data into a dictionary like

5条回答
  •  清歌不尽
    2021-02-01 07:51

    i did not type this in visual studio so you might need to make minor changes to make it run...

    Dictionary(int key,string value) dictionary = new Dictionary();
    
    foreach(DataRow row in DataTable.Rows)
    {
       //null check??
       dictionary.add(Convert.toInt(row[0]),row[1].toString());
    }
    

    try that ... see if that helps.

提交回复
热议问题