【发布时间】:2011-05-18 17:07:43
【问题描述】:
您好,我想用从 Oracle 数据库获取的数据填写一个列表。 但它总是给我错误。
这是我的连接类
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Windows.Forms;
namespace Kunst_In_Huis_C
{
class Connectie
{
String strApplicationName = Application.ProductName;
Logging objLoggingApplication = new Logging("d:\\project.log");
private OracleConnection con;
public Connectie()
{
con = new OracleConnection();
}
public void openConnectie()
{
if (con.State == ConnectionState.Closed)
{
con = new OracleConnection("Data Source=192.168.1.106/orcl;User ID=???;Password=???;Unicode=True");
con.Open();
}
}
public void sluitConnectie()
{
try
{
this.con.Close();
}
catch (Exception)
{
Console.WriteLine("fout bij het afsluiten van de connectie...");
}
}
public void voerQueryUit(String sql)
{
try
{
OracleCommand cmd = new OracleCommand(sql, con);
OracleDataReader oradr = cmd.ExecuteReader();
while (oradr.Read())
{
Console.WriteLine(oradr.GetInt32(0) + " \t " + oradr.GetString(1));
}
oradr.Close();
}
catch (OracleException ex)
{
Console.WriteLine("Oracle Error\n" + ex.Message);
}
catch (Exception ex)
{
Console.WriteLine("General App Error" + ex.Message);
}
finally
{
con.Close();
}
}
public void VulFilialen()
{
try
{
OracleCommand cmd = new OracleCommand("Select Fil_Adres from Filialen", con);
OracleDataReader oradr = cmd.ExecuteReader();
List<String> Filialen = new List<String>();
oradr = cmd.ExecuteReader();
while (oradr.Read())
{
Filialen.Add(oradr(0));
}
return Filialen;
}
catch (Exception ex)
{
objLoggingApplication.WriteLine(strApplicationName, ex.Message);
}
finally
{
con.Close();
}
}
}
}
它在我返回时总是给我错误,当我想在列表中添加一些东西时。
【问题讨论】:
-
错误是什么?完成后还要处理您的连接/命令/等对象。
-
oradr = cmd.ExecuteReader()你为什么要这样做两次?
标签: c# oracle list connection