System exception error in Oracle

Posted on 2014-07-15
Last Modified: 2014-07-15
Hi Everyone,

I have the below code and it throws a system exception error.  And, I don't see anything what is causing the error.

private String GetEntityNames(string tableName)
            string e = null;
            string ConString = "User Id=sys;Password=sys;Data Source=T";
            using (OracleConnection con = new OracleConnection(ConString))
                OracleDataAdapter adapter = new OracleDataAdapter();
                OracleCommand command = new OracleCommand("SELECT Y_NUMBER FROM T.E WHERE E_N=" + tableName, con); 
                adapter.SelectCommand = command;
                DataSet dataset = new DataSet("PSR");
                foreach (DataRow dr in dataset.Tables[0].Rows)
                   eNumber = dr["Y_NUMBER"].ToString();

            return eNumber;

Open in new window

Can you please help around this?

Question by:o0JoeCool0o
    LVL 29

    Expert Comment

    Difficult to say if you keep the error message(s) a secret.
    LVL 4

    Author Comment

    It says 'ORA:00904 Invalid identifier'.
    LVL 74

    Accepted Solution

    If the type of the column "E_N" is VARCHAR/VARCHAR2, then you need to have a string in your query (i.e. single quote it):

    OracleCommand command = new OracleCommand("SELECT Y_NUMBER FROM T.E WHERE E_N='" + tableName + "'", con);

    Open in new window

    But keep in mind that building a query by string concatenation opens you up for SQL Injection attacks. It would be better to use parameterized queries.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
    This article will show, step by step, how to integrate R code into a R Sweave document
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now