Issue while reading excel column names by using GetOleDbSchemaTable

After some google searching I found out how to read excel column names How To Retrieve Schema Information by Using GetOleDbSchemaTable and Visual Basic .NET . Though the sample is in VB.Net, I am using C#.net. My code is :

public DataSet ReadXslToDataset(string fileName,string sheetName) { ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+fileName+";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"; using (objConn = new OleDbConnection(ConnectionString)) { objConn.Open(); String[] restrection = { null, null, sheetName, null }; dtColumnNames = objConn.GetOleDbSchemaTable (OleDbSchemaGuid.Columns, restrection); string strColumnName = string.Empty; if (dtColumnNames != null) strColumnName = dtColumnNames.Rows[0]["COLUMN_NAME"].ToString(); } }

But I am finding that the column field is blank and henceforth getting the exception

There is no row at position 0.

The excel file looks as

S.No Issue 1 log4net message pattern not displayed properly in the log file 2 Reading blank rows from Excel while populating into dataset

and I have ensured that I am passing the right file & sheet name.

-------------Problems Reply------------

There is no row at position 0.

Try

if (dtColumnNames != null) {
if(dtColumnNames.Rows.Count > 0){
strColumnName = ColumnNames.Rows[0]["COLUMN_NAME"].ToString
}
}

Sorry I may have the syntax slightly out - I'm more of a VB.net guy.

Category:.net Views:3 Time:2010-05-05
Tags: .net excel c# 3.0

Related post

  • How to hide an excel column? 2012-01-11

    I need to hide an excel column entirely. I used the below code but didn't work: public void Hide (params string[] columns) { foreach(var column in columns) { Range range = (Range) oSheet.Columns[column, Type.Missing]; range.EntireColumn.Hidden = true

  • How do I find the Excel column name that corresponds to a given integer? 2008-08-22

    This question already has an answer here: How to convert a column number (eg. 127) into an excel column (eg. AA) 32 answers How would you determine the column name (e.g. "AQ" or "BH") of the nth column in Excel? Edit: A language-agnostic algorithm to

  • How to convert a column number (eg. 127) into an excel column (eg. AA) 2008-10-08

    How do you convert a numerical number to an Excel column name in C# without using automation getting the value directly from Excel. Excel 2007 has a possible range of 1 to 16384, which is the number of columns that it supports. The resulting values s

  • What is the algorithm to convert an Excel Column Letter into its Number? 2009-03-20

    I need an algorithm to convert an Excel Column letter to its proper number. The language this will be written in is C#, but any would do or even pseudo code. Please note I am going to put this in C# and I don't want to use the office dll. For 'A' the

  • Programming Riddle: How might you translate an Excel column name to a number? 2009-04-18

    I was recently asked in a job interview to resolve a programming puzzle that I thought it would be interesting to share. It's about translating Excel column letters to actual numbers, if you recall, Excel names its columns with letters from A to Z, a

  • Fastest function to generate Excel column letters in C# 2009-05-07

    What is the fastest c# function that takes and int and returns a string containing a letter or letters for use in an Excel function? For example, 1 returns "A", 26 returns "Z", 27 returns "AA", etc. This is called tens of thousands of times and is ta

  • How do I export a reporting services report to excel with embedded calculations in the excel columns? 2009-06-09

    I'm looking to allow the user to export an reporting service report to Excel. The question I have is how do I specify a formula within Reporting Service which is then present as an Excel column calcualtion on the exported file? Currently all I can se

  • Convert Number to Corresponding Excel Column 2009-08-13

    This question already has an answer here: How to convert a column number (eg. 127) into an excel column (eg. AA) 32 answers I need some help in doing a logic that would convert a numeric value to corresponding MS Excel header value. For example: 1 =

  • Format Excel column as text 2011-02-10

    Possible Duplicate: C# extract formatted text from Excel through OLEDB Can i somehow format an excel column and it's data as text, before fetching the data from it ? I'm using C# and .NET Framework 4.0 --------------Solutions------------- You can pre

  • VBA Word and using Excel columns as a lookup and replace 2011-03-30

    I have a MS Word Doc that has the wrong words in it when it comes to me. I have a list of these words in Excel column A of book1, sheet1. I also have what the words should be column B of book1, sheet1. The list is about 300 words but the doc is only

  • Issue After Converting Table Column From "Text" to Varchar(max) 2011-04-28

    I had a table called Person with column PersonDescription which was of type "text". I had issues with updating this column so i ran the script ALTER TABLE dbo.Person ALTER COLUMN PersonDescription VARCHAR(max) to change the column to be varchar(max).

  • How to import multiple Excel columns into single SQL Server column? 2011-09-21

    We import a lot of data files (mostly Excel, sometimes CSV) from different sources into SQL Server databases. The data files have some common fields (name, address, etc.) and usually other fields - some we need/use and some that we don't need. How co

  • Unable to paste MS-Excel column into SWT's Text widget 2011-12-08

    I have SWT Text widget which is created with SWT.SINGLE style e.g. Text myTextControl = new Text(shell, SWT.SINGLE); Now, when I try to copy column from MS-Excel only first of that selected column gets pasted into Text widget and not entire column. I

  • how to split string copied from excel column? (using jQuery) 2011-12-16

    I want the way to split string copied from excel column. I want to use that copied string in jQuery. But problem is that when we copy any column from excel then it gives that column data as single string. I am developing an application in asp.net in

  • Converting Excel Column with To SSRS (inch or pt) 2012-04-12

    I have report in Excel that I user gave me and wants the same exact format in the new SSRS report. So if I have a column in excel of the width 14.14 (103 pixels) what should that be for the width of that column in SSRS ( in, mm, cm, pt, or pc)? I can

  • LinqToExcel: Distinct values in excel column 2012-05-02

    This might be a very simple thing for you gurus, but I'm not familiar with C#4 and INTEROP. Therefore, I'm stumped. Here's my problem. I have a excel column that has duplicate data and I want to trim it down to only unique values. Here's what the dat

  • During mail merge, I want Word to use excels COLUMN DATA as the header, not the first ROW. How is this possible? 2012-01-22

    During mail merge into Microsoft WORD, I want Word to use excels COLUMN DATA as the header, not the first ROW. How is this possible? --------------Solutions------------- I don't think that is possible. For mail merge, the data source must be a databa

  • Having a Issue with Microsoft Excel upon start up and log off. I keep getting the Error Signature 2012-02-06

    Having a Issue with Microsoft Excel upon start up and log off. I keep getting the Error Signature below. Error Signature - AppName excel.exe, AppVer:14.0.4756.1000, AppStamp: 4b9c08e8, ModName: msvcrt.dll, ModVer: 7.0.2600.5512, ModStamp: 4802a188, f

  • Excel column labels, numeric 2012-05-30

    Excel column labels have changed to numeric rather than Alpha. How can I change back? --------------Solutions------------- Click the Office Button (the large circular icon in the upper left corner of the window), click the Excel Options button at the

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.191 (s). 11 q(s)