We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,379 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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?

2
Contributors
3
Replies
2 Hours
Discussion Span
2 Years Ago
Last Updated
5
Views
man3388
Newbie Poster
4 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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,736 posts since Oct 2008
Reputation Points: 2,141
Solved Threads: 1,262
Skill Endorsements: 50

>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
Skill Endorsements: 0

Not sure what you want.

Add two column name:

Hashtable ExcelSheets = new Hashtable();

ExcelSheets.Add(dt1.Columns[0].ColumnName,dt1.Columns[1].ColumnName)
__avd
Posting Genius (adatapost)
Moderator
8,736 posts since Oct 2008
Reputation Points: 2,141
Solved Threads: 1,262
Skill Endorsements: 50

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0621 seconds using 2.65MB