Click here to Skip to main content
15,882,113 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
i'm using below code to retrieve date from oracle db. i'm using oracle client 11.2.0.
when i copied query to SQL Developer, query resulted rows.

do i have to configure oracle client 11.2.0 to be able to use it ? or what i have to do to be able to get desired result ?

Thanks in advance.

What I have tried:

C#
public static System.Data.DataTable GetOracleDataTable(string Query, string tblName)
        {
            System.Data.DataSet dSet = new System.Data.DataSet();

            OracleConnection con = new OracleConnection(Globals.OracleConnectionString) ;
           
            OracleCommand cmd = new OracleCommand();           
            cmd.Connection = con;
            cmd.CommandText = Query;

            OracleDataAdapter adapter = new OracleDataAdapter(cmd);           
            adapter.Fill(dSet, tblName);
           
            return dSet.Tables[tblName];
            
        }
Posted
Updated 18-Apr-18 11:44am
Comments
Richard MacCutchan 18-Apr-18 8:01am    
What is the query, what is the result you see ... ?
[no name] 18-Apr-18 9:06am    
cmd.CommandType = CommandType.Text;
Abdullah... 19-Apr-18 2:25am    
Thanks,
i have added the line above but nothing changed.
Richard Deeming 19-Apr-18 16:17pm    
"i'm adding condition directly without using parameters"

Don't do that. Not unless you want someone to destroy your database, and to have to pay a large fine for exposing your customers' personal data.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]

1 solution

Replace your code with below snippet and it should work.

public static System.Data.DataTable GetOracleDataTable(string Query, string tblName)
{
    System.Data.DataSet dSet = new System.Data.DataSet();
    
    OracleConnection con = new OracleConnection(Globals.OracleConnectionString) ;
    con.Open();

    OracleCommand cmd = new OracleCommand(Query);           
    cmd.Connection = con;
    cmd.CommandText = CommandType.Text;
    
    OracleDataAdapter adapter = new OracleDataAdapter(cmd);           
    adapter.Fill(dSet, tblName);

return dSet.Tables[tblName];
}
 
Share this answer
 
v3
Comments
Abdullah... 19-Apr-18 2:20am    
Thanks,
but Oracle Connection constructor does not accept two parameters.
[no name] 19-Apr-18 10:32am    
Updated code
RonnieDean77 30-Jan-19 18:28pm    
Did you find a solution? I tried the provided solution above but I still get no results in C# and SQL Developer has LOTS of rows. What the heck am I missing here?
[no name] 5-Feb-19 9:09am    
Is your query correct if you run it to fetch any data?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900