• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 560
  • Last Modified:

System exception error in Oracle

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();
                con.Open();
                OracleCommand command = new OracleCommand("SELECT Y_NUMBER FROM T.E WHERE E_N=" + tableName, con); 
                   
                adapter.SelectCommand = command;
                DataSet dataset = new DataSet("PSR");
                adapter.Fill(dataset);
                foreach (DataRow dr in dataset.Tables[0].Rows)
                {
                   
                   eNumber = dr["Y_NUMBER"].ToString();
                }
                con.Close();
            }

            return eNumber;
        }

Open in new window


Can you please help around this?

Thanks.
0
o0JoeCool0o
Asked:
o0JoeCool0o
1 Solution
 
MikeOM_DBACommented:
Difficult to say if you keep the error message(s) a secret.
0
 
o0JoeCool0oAuthor Commented:
It says 'ORA:00904 Invalid identifier'.
0
 
käµfm³d 👽Commented:
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.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now