Davideg Davideg - 4 months ago 61
Vb.net Question

how to fill system.data.dataset from oracle.dataacess.client.oracledataadapter?

Greetings,

I have installed Oracle 10g Express Edition database on a server and install the client on my PC.

Now, I`m developing a vb.net application using visual studio 2005 and I need to use the oracle 10g express edition database. SO I initialize the connection using the following connection string:

_connectionString = "User Id=Graphya;Password=Graphya;Data Source=gis64:1522/XE;"


Then I define new OracleDataAdapter, and I use the following code to fill a dataset:

Dim insertCommand As OracleCommand = New OracleCommand()
Dim commandTextTemplate As String = "INSERT INTO {0}(" & g_pfldUsername & ", " & g_pfldSubject & ") VALUES (?, ?)"
insertCommand.CommandText = String.Format(commandTextTemplate,TABLE_NAME)
insertCommand.Connection = Me.Connection
insertCommand.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter(g_pfldUsername, Oracle.DataAccess.Client.OracleDbType.Varchar2, 50, g_pfldUsername))
insertCommand.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter(g_pfldSubject, Oracle.DataAccess.Client.OracleDbType.Varchar2, 50, g_pfldSubject))

_OracleDataAdapter.InsertCommand = insertCommand

_OracleDataAdapter.Fill(_dataSet, TABLE_NAME)


So after debugging this code I got the following error:

Unable to cast object of type 'Oracle.DataAccess.Client.OracleCommand' to type 'System.Data.Common.DbCommand'.

So I`m stuck here and I need a little help , please advise....

Thanks in advance..

Answer

@Davideg: my code is c# to fill data set

OleDbConnection cnOra = new OleDbConnection("Provider=MSDAORA;Data Source=myOracleServer;" 
              + "user id=myUID;password=myPWD;"
              + "persist security info=false;");
        OleDbCommand cmdPerson = new OleDbCommand
        + ("{call PackPerson.allPerson({resultset 3, ssn, fname, lname})}", cnOra);

    OleDbDataAdapter daPerson = new OleDbDataAdapter(cmdPerson);
    cnOra.Open();
    DataSet ds = new DataSet();
    daPerson.Fill(ds,"Person");
    this.dataGrid1.DataSource = ds.Tables["Person"];
    cnOra.Close();