tags:

views:

38

answers:

2

Well, the problem is as follows:

I have a WPF Application built using the C#, I have known how to connect to oracle database engine, yet I need some help in it.

first, I want to know how to add the server to the connection string ...

OleDbConnection conn = new OleDbConnection("provider=MSDAORA;data source=ORCL;user id=SCOTT;password=TIGER");

is it the provider or the data source? and the server is on my pc should I write it localhost or 127.0.0.1 then the port? and how do I add the port is it server:port or should I add another parameter?

second, I have created a function that executes a query sent to it as a parameter, I want to put the query result in a DataSet yet I don`t know how to convert the result to a DataSet.

This is my function:

public DataSet SelectQuery(String p_sSql)
    {
        DataSet ds = new DataSet();
        try
        {
            OleDbCommand myOleDbCommand = conn.CreateCommand();
            myOleDbCommand.CommandText = p_sSql.ToString();
            OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();
            myOleDbDataReader.Read();
            //here I want to add the result to the DataSet ds ...
            myOleDbDataReader.Close();
            conn.Close();
            return ds;
        }
        catch (System.Exception ex)
        {
            MessageBox.Show("Error: " + ex.ToString());
            return null;
        }
    }
+1  A: 

If you are not limited only to ODBC, you should try ODP.NET

http://www.oracle.com/technology/tech/windows/odpnet/index.html

And here is a simple tutorial

http://www.oracle.com/technology/pub/articles/cook-vs08.html

ZEAXIF
@ZEAXIF: I followed the instructions mentioned in the second link regarding the connection, yet I can`t figure out the correct connection string for my database, I`m using Oracle 10g XE, I don`t know what the provider and the data source should be.
sikas
Please check this out:http://www.connectionstrings.com/oracle
ZEAXIF
A: 

For an example of Oracle Connection strings Take a look at this URL as it will contain all of the info needed. connectionstrings.com/oracle. On another note unless you really need to don't bother with the ODP.Net provider as it is a pain to install and you will run into x64 issue with Oracle 10g. I find I have fewer problems using System.Data.OracleClient which is going to be deprecated in .Net 4.0 unfortunately.

As for specifying the Port typically all of that information is specified in your TNS file and you just specify which TNS listing to use in your connection string.

runxc1 Bret Ferrier