N
nm
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...
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...