Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
_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:

VB
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..
Posted

1 solution

Well, the error you are getting is that you have two different types of commands and you can't just set one to the other.

I really haven't used an OracleCommand before, but after reading the MSDN[^] on it....it doesn't look like it can do a FILL. It looks like it only has capabilities of reading one line at a time with a reader, or doing scalar or non query operations.

Also, I know you say you are using VS 2005, but the .NET Framework 4 says this API is now obsolete. So it's not something that you will ever be able to upgrade to in the next versions of Visual Studio....if you ever take this project and upgrade it.

So...My suggestion is to connection to the Oracle Database with a different provider. Here[^] is a tutorial on how to link to oracle using an ole db provider. The ole db provider has the ability to perform a fill operation.

And here[^] is a list of other ways you can connect.
 
Share this answer
 
v2
Comments
dgthecodeproject 4-Apr-12 1:31am    
Thank you very much for your help....
I did what you suggest and used OLEDB connection type which give me a good solution... But I need some more little advise over here: What is the Oledb datatypes corresponding to oracle datatypes(Number, Varchar2, TimeStamp).....Can you help me plz..
Kschuler 4-Apr-12 9:13am    
I'm not exactly sure how to respond to that. When you pull a oracle number using the oledb connection the datatable that you fill will probably convert the number into an integer or a decimal. And a varchar will probably convert to a string. Why do you need to know? Perhaps you should post another queston with this new question and explain exactly what you are trying to do and why it isn't working.
dgthecodeproject 5-Apr-12 0:24am    
Thanks a lot Kschuler for your advise...I may post a new question on that as you said....

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