473,385 Members | 1,602 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,385 software developers and data experts.

Inline SQL problem

SAL
Hello,

I'm developing a APP that reads an Excel spreadsheet, does data
manipulation, and writes to a SQL Server table. I working with C#, Visual
Studio 2003, and Framework 1.1. When I connect to the Excel workbook I'm
using OLEDB.

The problem I'm have is with my In-line SQL having spaces in the Column
Headings. Here's a code snippet of my Sql:

string sqlCommand = "Select 'Invoice #','Invoice Date','Equipment
ID','Invoice Line Item Amount','Authorization #' " +
"From [InvoiceTemplate$]";

It is failing when I execute the sqlCommand because our vendors are sending
us Column headings with spaces and # signs. I created a dummy workbook with
normal column headings, and no spaces or special characters and I connected
fine.

Has anyone ran into this problem? If so, how did you handle it?

Thanks,
Sep 13 '06 #1
5 1506
SELECT [Invoice #], [Invoice Date], [Equipment ID] etc

Watch out for columns with ] in them ;-p (blah blah SQL injection blah blah
concatenating blah parameters blah - not always possible if the schema is
dynamic...)

Of course, if you want to read all the columns from a single table, then
SELECT * may be a reasonable choice *in this case* (only). I wouldn't
normally recommend this, but it could save you from a lot of problems...

Marc
Sep 13 '06 #2
Sorry - on first glance I thought the problem was in reading from the
uploaded table (in SQL Server) - not sure if this syntax will be friendly to
Excel - worth a try, though!

Marc
Sep 13 '06 #3
Hi,

you can use [] to enclose the columns. Another possibility is to simply do a
SELECT *

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Sep 13 '06 #4
SAL
Nope, the [] did not work. I even tried qualifing the table name with an
alias and that did not work.

"SAL" wrote:
Hello,

I'm developing a APP that reads an Excel spreadsheet, does data
manipulation, and writes to a SQL Server table. I working with C#, Visual
Studio 2003, and Framework 1.1. When I connect to the Excel workbook I'm
using OLEDB.

The problem I'm have is with my In-line SQL having spaces in the Column
Headings. Here's a code snippet of my Sql:

string sqlCommand = "Select 'Invoice #','Invoice Date','Equipment
ID','Invoice Line Item Amount','Authorization #' " +
"From [InvoiceTemplate$]";

It is failing when I execute the sqlCommand because our vendors are sending
us Column headings with spaces and # signs. I created a dummy workbook with
normal column headings, and no spaces or special characters and I connected
fine.

Has anyone ran into this problem? If so, how did you handle it?

Thanks,
Sep 13 '06 #5
SAL
Another issue I'm running into is when PROTECT SHEET & PROTECT WORKBOOK are
turned on.

When working with OLEDB & C#, are there additional OLEDB parameters my C#
program needs to pass when these switches are turned on?

Thanks,
"SAL" wrote:
Hello,

I'm developing a APP that reads an Excel spreadsheet, does data
manipulation, and writes to a SQL Server table. I working with C#, Visual
Studio 2003, and Framework 1.1. When I connect to the Excel workbook I'm
using OLEDB.

The problem I'm have is with my In-line SQL having spaces in the Column
Headings. Here's a code snippet of my Sql:

string sqlCommand = "Select 'Invoice #','Invoice Date','Equipment
ID','Invoice Line Item Amount','Authorization #' " +
"From [InvoiceTemplate$]";

It is failing when I execute the sqlCommand because our vendors are sending
us Column headings with spaces and # signs. I created a dummy workbook with
normal column headings, and no spaces or special characters and I connected
fine.

Has anyone ran into this problem? If so, how did you handle it?

Thanks,
Sep 13 '06 #6

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

Similar topics

46
by: DJ WIce | last post by:
Hi all, I did make a script/css thing to replace the contextmenu on the website with a new one: http://www.djwice.com/contextmenu.html It works nice in MSIE, but on Netscape (and probable...
23
by: Mat | last post by:
<div id="container"> <div id="main"> <div id="header"> <p class="Address">123 Fake Street, </p> <p class="City">Crazy City, </p> <p class="Province">Ontario </p> <p class="PostalCode">H0H...
47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
4
by: Tony Johansson | last post by:
Hello experts! I'm reading a book about C++ and there is something about inline that the book says that is unclear for me. The book says the following "Because inline functions are expanded at...
5
by: Tony Johansson | last post by:
Hello experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that sound strange. Here is the whole section: It says" Because...
18
by: Method Man | last post by:
If I don't care about the size of my executable or compile time, is there any reason why I wouldn't want to inline every function in my code to make the program run more efficient?
5
by: Ondrej Spanel | last post by:
I though that inline functions should be always visible only in the compilation unit where they are defined - meaning if compiler cannot inline them, they should be handled as if declared static....
6
by: axlq | last post by:
I've spent most of the day struggling with what I thought would be a trivial problem. I have a hidden element that appears, outside of the normal flow, when the mouse hovers over an inline...
12
by: sam_cit | last post by:
Hi Everyone, I have few questions on inline functions, when i declare a function as inline, is it for sure that the compiler would replace the function call with the actual body of the function?...
11
by: totalstranger | last post by:
I have a check box with let's say 20 elements. I would like to have it align as 4 columns, 5 rows. Without using a table and using understandable CSS is there any way to make the check boxes align...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.