如何从oracle.dataacess.client.oracledataadapter填充system.data.dataset? [英] how to fill system.data.dataset from oracle.dataacess.client.oracledataadapter?

查看:191
本文介绍了如何从oracle.dataacess.client.oracledataadapter填充system.data.dataset?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,

我已经在服务器上安装了Oracle 10g Express Edition数据库,并在我的PC上安装了客户端.

现在,我正在使用Visual Studio 2005开发vb.net应用程序,我需要使用oracle 10g快捷版数据库.因此,我使用以下连接字符串初始化连接:

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



然后定义新的OracleDataAdapter,并使用以下代码填充数据集:



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)



因此,在调试此代码后,出现以下错误:

无法将类型为"Oracle.DataAccess.Client.OracleCommand"的对象转换为类型为"System.Data.Common.DbCommand".

所以我被困在这里,需要一点帮助,请指教....


预先感谢..



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

推荐答案

好吧,您得到的错误是您有两种不同类型的命令,您可以只需将一个设置为另一个.

我以前确实没有使用过OracleCommand,但是在阅读了 MSDN 之后, a> [^ ]就可以了....看起来好像无法完成填充.看起来它只能与阅读器一次读取一行,或者执行标量或非查询操作.

另外,我知道您说您正在使用VS 2005,但是.NET Framework 4表示此API现在已过时.因此,如果您接受此项目并对其进行升级,那么您将无法在下一版本的Visual Studio中对其进行升级.

所以...我的建议是使用其他提供程序连接到Oracle数据库. 此处 [ ^ ]是有关如何使用ole db provider链接到oracle的教程. ole db提供程序可以执行填充操作.

此处 [
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.


这篇关于如何从oracle.dataacess.client.oracledataadapter填充system.data.dataset?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆