Search code examples
c#wpforacle-xe

C# Oracle Database 10g issues


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;
        }
    }

Solution

  • 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