Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / June 2004

Tip: Looking for answers? Try searching our database.

Column names with spaces in them giving me trouble

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nm - 10 Jun 2004 13:03 GMT
I am using .NET to insert a record into an Access Database. The Access
Database is coming from an external source and used by other applications, I
have no control over the column names. It has 3 columns, "First Name", "Last
Name", and "Work Email". As you can see, all 3 use a [space] in the column
title. Shame on whoever designed that database, but nevertheless I have to
deal with it. So anyway in C#, to insert a record, the SQL statement I'm
using is....

sqlStatement = "INSERT INTO MasterTable ('First Name', 'Last Name', 'Work
Email') VALUES ('" + "Bob" + "', '" + "Smith" + "','" +
Regex.Replace(tboxTestEmail.Text, @"'", @"''") + "')";

Which gets me the error...

Exception Details: System.Data.OleDb.OleDbException: The INSERT INTO
statement contains the following unknown field name: ''First Name''. Make
sure you have typed the name correctly, and try the operation again.

I have tried putting escaped " around the column names, to no avail (simliar
error). Leaving off the ' ' around the column names entirely gets me just a
general SQL Syntax error.

Not sure what else to try...
Jon Skeet [C# MVP] - 10 Jun 2004 13:24 GMT
> I am using .NET to insert a record into an Access Database. The Access
> Database is coming from an external source and used by other applications, I
[quoted text clipped - 3 lines]
> deal with it. So anyway in C#, to insert a record, the SQL statement I'm
> using is....

Try ([First Name], [Last Name] ...) instead.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

nm - 10 Jun 2004 14:04 GMT
Works! Thank you!

> > I am using .NET to insert a record into an Access Database. The Access
> > Database is coming from an external source and used by other applications, I
[quoted text clipped - 5 lines]
>
> Try ([First Name], [Last Name] ...) instead.
William Ryan eMVP - 10 Jun 2004 20:47 GMT
NM, just a word of advice on that.  Get rid of the spaces.  The odds are
pretty strong you or someone else is going to forget to do this and it'll
come up again and again and is probably going to end up being a lot more
headache than it's worth.

Signature

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/

> Works! Thank you!
>
[quoted text clipped - 11 lines]
> >
> > Try ([First Name], [Last Name] ...) instead.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.