当前位置:编程学习 > C#/ASP.NET >>

vc.net下用ado.net连接oracle的问题

我用的是.NET for Oracle组件,但在导入System.Data.OracleClient.dll时出错,报错如下:
f:\capabilitytest\stdafx.h(43) : fatal error C1083: 无法打开类型库文件:“c:\windows\microsoft.net\framework\v2.0.50727\system.data.oracleclient.dll”: 加载类型库/DLL 时出错。

原语句:
#import "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.OracleClient.dll"
System.Data.OracleClient.dll是存在的,我在网上查了很久,好象没有一条是适合我的,各位高手们进来帮帮忙!
先谢了! --------------------编程问答-------------------- 有没有知道的啊?进来帮帮我 --------------------编程问答-------------------- 无能为力
友情帮顶 --------------------编程问答-------------------- gz --------------------编程问答-------------------- 试试这样
#using <system.dll>
using namespace System;
#using <system.data.dll>
using namespace System::Data;
#using <system.data.OracleClient.dll>
using namespace System::Data::OracleClient; --------------------编程问答-------------------- 好像不行 --------------------编程问答-------------------- 关注中 --------------------编程问答-------------------- 想问一下,你的机器上安装了OCI相关的库吗?或者说,有Oracle客户端吗?如果没有的话,肯定出问题。 --------------------编程问答-------------------- 算了,干脆帮你写一个,得了。
好久没弄.net上的东东了,帮你写了一个,程序如下:

下边的A表有两个字段table A(int A, int B)

// oracle_ado.net.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
   
#using <mscorlib.dll>
#using <system.dll>
#using <system.data.dll>
#include <tchar.h>

#using  <system.dll> 
using namespace System; 
#using  <system.data.dll> 
using namespace System::Data; 
#using  <system.data.OracleClient.dll> 
using namespace System::Data::OracleClient;

void test_oracle()
{
    OracleConnection^ conn = gcnew OracleConnection("Data Source=ora92;User ID=scott;pwd=tiger;Unicode=True");
    OracleCommand^ command;
    command = gcnew OracleCommand("select * from A", conn);
    OracleDataReader^ rdr;
   
    try 
    {
        conn->Open();
        rdr = command->ExecuteReader();
   
        if(rdr->Read())
        {
            Console::Write("A: ");
    Console::Write(rdr->GetInt32(0));
            Console::Write("B: ");
            Console::WriteLine(rdr->GetInt32(1));
        }
    }
    catch (Exception^ e) 
    {
        System::Console::WriteLine(e->ToString());
    }
    __finally
    {
        conn->Close();
    }
}

// This is the entry point for this application
int _tmain(void)
{
    test_oracle();
    return 0;
}
上边的代码是可以直接运行的。
你的dll加载不成功,可能有别的客观原因。看看是否是framework安装不完整或是什么别的原因。

--------------------编程问答-------------------- 晕啊,居然不结帖。 --------------------编程问答-------------------- 有点难度哦 --------------------编程问答-------------------- 以后需再关注,现在先帮你顶一下 --------------------编程问答-------------------- 这个简单啊,网上搜一下就得到答案了. --------------------编程问答-------------------- 怎么和C# 没区别?哈哈
补充:.NET技术 ,  VC.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,