Add columnname and data from datatable to a dictionary? C#

Posted by Nick on Stack Overflow See other posts from Stack Overflow or by Nick
Published on 2011-02-11T06:50:07Z Indexed on 2011/02/11 7:25 UTC
Read the original article Hit count: 163

Filed under:

Hi,

I am looping through a datatable and currently I do

string customerId = row["CustomerId"].ToString();
string companyName = row["Company Name"].ToString();

Instead of declaring every variable how do I add these do a dictionary? I was thinking something like:

foreach (DataRow row in customerTbl.Rows)
    {
     Dictionary<string, string> customerDictionary = new Dictionary<string, string>();
     customerDictionary.Add(row[].ToString(), row[].ToString());

so yeah, how do I get the row name and value into there?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about c#