I have compiled a string that queries a database like so:
stringCompiler = "SELECT * FROM SomeTable";
The problem is that some of the columns have spaces in their names (i.e., “City Tag Number”).
How can I call this later after I use the db.Query statement. Example:
foreach(var row in db.Query(stringCompiler))
{
var someVariable = row.Column With Spaces;
}
Obviously the above code would produce an error.
I could go through each column instead of using ‘ * ‘, all the while assigning aliases to all of the column names with spaces in them. Example:
stringCompiler = "SELECT \"City Tag Number\" AS CityTagNumber, ...";
But there are a lot of column names in this table and I am assuming there is a better way, and that I just can’t find it (I promise, I’ve looked).
Any help is much appreciated.
—————-EDIT————————
I should’ve specified that I was using SqlServer.
In a sql text passed to the DB engine, usually (but it depends on the actual db) you use square brackets (SqlServer, Access) or backticks (mysql)
while in code (assuming row is a DataRow) you use the name of the column as string