473,322 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

C# and OLEDB issue

SAL
Hello,

I am using OLEDB to access Excel, and what I have read you can access Named
Ranges but I am having trouble doing so. The following are lines of code
I've tried in my C# program to access Named ranges but don't work. Is the
something else I need to do?

string sqlCommand = "Select * From [sheet1!DataExtract$]";
string sqlCommand = "Select * From [sheet1!$DataExtract$]";
string sqlCommand = "Select * From [DataExtract$]";

I can access my Excel Spreadsheet like this, string sqlCommand = "Select *
From [Sheet1$]"; WITHOUT any troubles. However, when I do the Select
statement it returns extra rows that are blank because it doesn't know which
cell was last used. If I can access the Named Range I can eliminate this
issue, but I don't if C# or OLEDB is preventing me from accessing the Named
Range. The following is the error it gives me for the 3 scenarios I tried:

"'sheet1!DataExtract$' is not a valid name. Make sure that it does not
include invalid characters or punctuation and that it is not too long."
"'sheet1!$DataExtract$' is not a valid name. Make sure that it does not
include invalid characters or punctuation and that it is not too long."
"'DataExtract$' is not a valid name. Make sure that it does not include
invalid characters or punctuation and that it is not too long."

I have verified the spelling is correct and that the Named Range exists, and
I still get this error message. Has anyone encounter this before? If so,
how did you fix it?

Thanks,
Sep 19 '06 #1
4 5577
Hi,

Not sure if you can access a named range using OleDB, you can always try to
use automation

Take a look at : http://support.microsoft.com/kb/302084/
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"SAL" <SA*@discussions.microsoft.comwrote in message
news:B8**********************************@microsof t.com...
Hello,

I am using OLEDB to access Excel, and what I have read you can access
Named
Ranges but I am having trouble doing so. The following are lines of code
I've tried in my C# program to access Named ranges but don't work. Is the
something else I need to do?

string sqlCommand = "Select * From [sheet1!DataExtract$]";
string sqlCommand = "Select * From [sheet1!$DataExtract$]";
string sqlCommand = "Select * From [DataExtract$]";

I can access my Excel Spreadsheet like this, string sqlCommand = "Select *
From [Sheet1$]"; WITHOUT any troubles. However, when I do the Select
statement it returns extra rows that are blank because it doesn't know
which
cell was last used. If I can access the Named Range I can eliminate this
issue, but I don't if C# or OLEDB is preventing me from accessing the
Named
Range. The following is the error it gives me for the 3 scenarios I
tried:

"'sheet1!DataExtract$' is not a valid name. Make sure that it does not
include invalid characters or punctuation and that it is not too long."
"'sheet1!$DataExtract$' is not a valid name. Make sure that it does not
include invalid characters or punctuation and that it is not too long."
"'DataExtract$' is not a valid name. Make sure that it does not include
invalid characters or punctuation and that it is not too long."

I have verified the spelling is correct and that the Named Range exists,
and
I still get this error message. Has anyone encounter this before? If so,
how did you fix it?

Thanks,

Sep 19 '06 #2
SAL
Hi,

Well, I was wondering if it might be OLEDB. I'm tring to you use OLEDB
since I could have multiple excel file reads a day, and with different names,
and writing to SQL Server.

I'm going to look into OLEDB a little further before I take the route you
pointed me to.

Thanks,
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

Not sure if you can access a named range using OleDB, you can always try to
use automation

Take a look at : http://support.microsoft.com/kb/302084/
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"SAL" <SA*@discussions.microsoft.comwrote in message
news:B8**********************************@microsof t.com...
Hello,

I am using OLEDB to access Excel, and what I have read you can access
Named
Ranges but I am having trouble doing so. The following are lines of code
I've tried in my C# program to access Named ranges but don't work. Is the
something else I need to do?

string sqlCommand = "Select * From [sheet1!DataExtract$]";
string sqlCommand = "Select * From [sheet1!$DataExtract$]";
string sqlCommand = "Select * From [DataExtract$]";

I can access my Excel Spreadsheet like this, string sqlCommand = "Select *
From [Sheet1$]"; WITHOUT any troubles. However, when I do the Select
statement it returns extra rows that are blank because it doesn't know
which
cell was last used. If I can access the Named Range I can eliminate this
issue, but I don't if C# or OLEDB is preventing me from accessing the
Named
Range. The following is the error it gives me for the 3 scenarios I
tried:

"'sheet1!DataExtract$' is not a valid name. Make sure that it does not
include invalid characters or punctuation and that it is not too long."
"'sheet1!$DataExtract$' is not a valid name. Make sure that it does not
include invalid characters or punctuation and that it is not too long."
"'DataExtract$' is not a valid name. Make sure that it does not include
invalid characters or punctuation and that it is not too long."

I have verified the spelling is correct and that the Named Range exists,
and
I still get this error message. Has anyone encounter this before? If so,
how did you fix it?

Thanks,


Sep 19 '06 #3
SAL
Turns out you can do it the way I'm doing it, but DO NOT USE the $ sign at
the end when calling a Named Range. You still need it when calling a
worksheet. I.E:

For calling a Worksheet
string sqlCommand = "Select * From [sheet1$]";

For calling Named Range
string sqlCommand = "Select * From [NamedRange]";

Once I changed it to what I just showed, everything worked like a charm.

Thanks,

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

Not sure if you can access a named range using OleDB, you can always try to
use automation

Take a look at : http://support.microsoft.com/kb/302084/
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"SAL" <SA*@discussions.microsoft.comwrote in message
news:B8**********************************@microsof t.com...
Hello,

I am using OLEDB to access Excel, and what I have read you can access
Named
Ranges but I am having trouble doing so. The following are lines of code
I've tried in my C# program to access Named ranges but don't work. Is the
something else I need to do?

string sqlCommand = "Select * From [sheet1!DataExtract$]";
string sqlCommand = "Select * From [sheet1!$DataExtract$]";
string sqlCommand = "Select * From [DataExtract$]";

I can access my Excel Spreadsheet like this, string sqlCommand = "Select *
From [Sheet1$]"; WITHOUT any troubles. However, when I do the Select
statement it returns extra rows that are blank because it doesn't know
which
cell was last used. If I can access the Named Range I can eliminate this
issue, but I don't if C# or OLEDB is preventing me from accessing the
Named
Range. The following is the error it gives me for the 3 scenarios I
tried:

"'sheet1!DataExtract$' is not a valid name. Make sure that it does not
include invalid characters or punctuation and that it is not too long."
"'sheet1!$DataExtract$' is not a valid name. Make sure that it does not
include invalid characters or punctuation and that it is not too long."
"'DataExtract$' is not a valid name. Make sure that it does not include
invalid characters or punctuation and that it is not too long."

I have verified the spelling is correct and that the Named Range exists,
and
I still get this error message. Has anyone encounter this before? If so,
how did you fix it?

Thanks,


Sep 19 '06 #4
Hi,
Good to know it worked for you.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"SAL" <SA*@discussions.microsoft.comwrote in message
news:F5**********************************@microsof t.com...
Turns out you can do it the way I'm doing it, but DO NOT USE the $ sign at
the end when calling a Named Range. You still need it when calling a
worksheet. I.E:

For calling a Worksheet
string sqlCommand = "Select * From [sheet1$]";

For calling Named Range
string sqlCommand = "Select * From [NamedRange]";

Once I changed it to what I just showed, everything worked like a charm.

Thanks,

"Ignacio Machin ( .NET/ C# MVP )" wrote:
>Hi,

Not sure if you can access a named range using OleDB, you can always try
to
use automation

Take a look at : http://support.microsoft.com/kb/302084/
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"SAL" <SA*@discussions.microsoft.comwrote in message
news:B8**********************************@microso ft.com...
Hello,

I am using OLEDB to access Excel, and what I have read you can access
Named
Ranges but I am having trouble doing so. The following are lines of
code
I've tried in my C# program to access Named ranges but don't work. Is
the
something else I need to do?

string sqlCommand = "Select * From [sheet1!DataExtract$]";
string sqlCommand = "Select * From [sheet1!$DataExtract$]";
string sqlCommand = "Select * From [DataExtract$]";

I can access my Excel Spreadsheet like this, string sqlCommand =
"Select *
From [Sheet1$]"; WITHOUT any troubles. However, when I do the Select
statement it returns extra rows that are blank because it doesn't know
which
cell was last used. If I can access the Named Range I can eliminate
this
issue, but I don't if C# or OLEDB is preventing me from accessing the
Named
Range. The following is the error it gives me for the 3 scenarios I
tried:

"'sheet1!DataExtract$' is not a valid name. Make sure that it does not
include invalid characters or punctuation and that it is not too long."
"'sheet1!$DataExtract$' is not a valid name. Make sure that it does
not
include invalid characters or punctuation and that it is not too long."
"'DataExtract$' is not a valid name. Make sure that it does not
include
invalid characters or punctuation and that it is not too long."

I have verified the spelling is correct and that the Named Range
exists,
and
I still get this error message. Has anyone encounter this before? If
so,
how did you fix it?

Thanks,



Sep 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: | last post by:
Hi, I was performing SQL UPDATE queries and I notice that they SUCCEED on the ExecuteNonQuery() call with NO exceptions raised BUT they fail at the Database. They say they succeed in the code...
8
by: bob | last post by:
Hi.. I'm making a OleDb connection to a access database.. I can fill the dataset fine and view the data, but when I add a new row and try to update the db I get this error. Any help would be...
1
by: Brian Henry | last post by:
I have an access database, and one of the fields in the table I am inserting into has a date/time data type. What is the correct OleDb data type to insert the date and time that it is at the moment...
0
by: Bijoy Naick | last post by:
I am using ASP.NET with an Access database. When I issue a ExecuteNonQuery operation, it fails. So I print out the sql statment, and the exception info.. Here it is.. I am unable to find the...
1
by: Siegfried Heintze | last post by:
I'm using a third party hosting service. I presently have a Web Service on this hosting service's server that loads and executes a native mode DLL. This demonstrates that the hosting service has...
13
by: Ron L | last post by:
I am working on an application that is a front-end for a SQL database. While it is not an immediate requirement, the application will probably be required to be able to connect via the internet at...
5
by: Jesse Albert | last post by:
Hiyo, I'm trying to import a CSV file into a datatable using either ODBC or OLEDB. One of the columns contains an IP Address. For some reason, the IP address will not display correctly. All of...
0
by: varughmi | last post by:
A unique issue has cropped up today in a .NET program I developed. It has been working fine for over an year until now. The program makes 2 connections total - one to a UNIT instance and another...
1
by: sirinath | last post by:
Hi, Is there a known issue in using Access through OleDB provider in C# (.NET Framework 2.0) where inserted records are not reflected in subsequent queries. Worst still, if the PK is a auto...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.