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?

>What 2 do?

Please elaborate on your question.

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

>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 ?

Not sure what you want.

Add two column name:

Hashtable ExcelSheets = new Hashtable();

ExcelSheets.Add(dt1.Columns[0].ColumnName,dt1.Columns[1].ColumnName)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.