1

I have created a web application which uses Database as MSACCESS, one of the column name in MSACCESS is separated with space something like "Employee Name".

My c# code is failing and not able to read the column name which has space between two words. I cannot change the column name as it was used by many applications.

Can i dynamically add underscore or remove the space in a specific column.

Or can someone suggest the best approach for this.

SELECT 
    Format([empdate],'mm') AS Month, 
    Sum([Time]) as MyTime 
    Format([empdate],'yyyy') as CurrYear 
FROM Table 
where empName ='" + AND ManagerName='XYZ' 
Group by Format([empdate],'mm') ,Format([empdate],'yyyy') 

in the query say empdate is emp date and ManagerName is Manager Name - i am getting exception while executing in c#

Smandoli
  • 6,919
  • 3
  • 49
  • 83
New Coder
  • 501
  • 2
  • 6
  • 23
  • are you reading column names or column data? – Damith Apr 14 '14 at 15:08
  • Can you use a query which aliases those column names to avoid whatever problems they're causing in your c# code? `SELECT [Employee Name] AS Employee_Name FROM YourTable;` – HansUp Apr 14 '14 at 15:19
  • I am retrieving column data based on column name say - SELECT Format([empdate],'mm') AS Month, Sum([Time]) as MyTime Format([empdate],'yyyy') as CurrYear FROM Table where empName ='" + drpdownstaffName.SelectedItem.Text + "' AND ManagerName='XYZ' Group by Format([empdate],'mm') ,Format([empdate],'yyyy') - in the query say empdate is emp date and ManagerName is Manager Name - i am getting exception while executing in c# – New Coder Apr 14 '14 at 15:33
  • That would not produce valid Access SQL. Your prospects for success will improve if you can start by building and testing your `SELECT` statement in the Access query designer. – HansUp Apr 14 '14 at 15:48
  • @Dipesh - Please do not add code to a comment! Edit your question and add the code there. – Chris Dunaway Apr 14 '14 at 16:35
  • @Dipesh - after "as MyTime" I believe you need a comma. And have you tried adding [] square brackets around the 3 column names that have embedded space? Did that solve it? tkx – donPablo Apr 15 '14 at 07:19

0 Answers0