954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to add two column fields into hashtable? [code added]

I want to add first two columns of excel file into hashtable.. I wrote following code but it is giving me eror saying indexing not allowed in datacolumn...

Hashtable ExcelSheets = new Hashtable();
System.Data.DataColumn dc;
            // adding excel file into hash table
            if (dt1.Columns.Count > 0)
            {
                for (int c = 0; c < dt1.Columns.Count; c++)
                {

                   
                   
                    try
                    {
                        ExcelSheets.Add(dc[0].ToString().ToLower(), dc[1].ToString().ToLower());
                        
                    }

                    catch (Exception)
                    {

                    }

                }
            }

What 2 do?

man3388
Newbie Poster
4 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

>What 2 do?

Please elaborate on your question.

Error says: indexing not allowed in datacolumn...so don't use indexing.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

>What 2 do?

Please elaborate on your question.

Error says: indexing not allowed in datacolumn...so don't use indexing.

Then what is the alternate method of adding two columns in hashtable?
Indexing is allowed in datarow ... can we do it using data row ?... how ?

man3388
Newbie Poster
4 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

Not sure what you want.


Add two column name:

code]
Hashtable ExcelSheets = new Hashtable();

ExcelSheets.Add(dt1.Columns[0].ColumnName,dt1.Columns[1].ColumnName)
[/code]

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: