Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8178273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:43:23+00:00 2026-06-06T23:43:23+00:00

I am having an excel sheet. I write a query in a particular cell

  • 0

I am having an excel sheet. I write a query in a particular cell in that excel sheet and then call that query through my C# code. I have declared that cell as strParam1. So, strParam1 contains whatever query I type in my excel sheet. The code is as follows:-

public void UpdateDatabase(String strParam1, int row)
        {
            System.Data.OracleClient.OracleConnection conn = new System.Data.OracleClient.OracleConnection();
            conn.ConnectionString = "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.144)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = orcl)));UID=mwm;PWD=mwm";
            try
            {
                conn.Open();
                OracleCommand command = conn.CreateCommand();
                command.CommandText = strParam1.Trim();
                OracleDataReader reader = command.ExecuteReader();
                command.Dispose();
            }
            catch (Exception ex)
            {
                ExcelRecorder(ex.Message, row);
            }
            finally
            {
                conn.Close();
            }
        }

When ExecuteReader is reached, it throws an exception “Invalid character” found. In the excel sheet, I have typed Select * from \”Task\”;
Since Task is an oracle keyword, I have restructured the above query. But, the query is not executing. If I type the below code and run it, everything is fine.

command.CommandText = "Select * from \"Task\""; 

What is wrong? Is there any special formatting I must do? And there is no problem in reading from the excel sheet. I tested it thoroughly. So, that has got to do nothing with my exception.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:43:24+00:00Added an answer on June 6, 2026 at 11:43 pm

    When you read the string from the Excel cell and put inside a string variable complete with quotes, you don’t need to add the \ to escape.
    To prove it, just put a breakpoint on the UpdateDatabase method and look at the strParam1 var.
    You could see that it contains the quotes, while when you assign the directly to the command.CommandText you need to escape the string literal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble with some Excel data validation. On one sheet, I have a
I am having an issue is that while exporting a report to excel sheet,
I have created a tool that imports an excel sheet. The excel COM object
I have an excel sheet with some cells having some background color. I need
I'm trying to call an Excel macro that's in another workbook. It's a sheet-specific
I have one excel Sheet having below records id Empname state 1 steve NJ
I have an excel sheet having three worksheets, I am having trouble in fetching
I'm having some trouble with looping and creating MS Excel docs, code snippet below
I am having some trouble with macros in my excel workbook. I have a
I have an Excel workbook that is used as a starting point to generate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.