好吧,问题如下:
我有一个使用 C# 构建的 WPF 应用程序,我知道如何连接到 oracle 数据库引擎,但我需要一些帮助。
首先,我想知道如何将服务器添加到连接字符串...
OleDbConnection conn = new OleDbConnection("provider=MSDAORA;data source=ORCL;user id=SCOTT;password=TIGER");
是提供者还是数据源?服务器在我的电脑上我应该写它localhost
还是127.0.0.1
端口?以及如何添加端口是它server:port
还是应该添加另一个参数?
其次,我创建了一个执行作为参数发送给它的查询的函数,我想将查询结果放入一个DataSet
但我不知道如何将结果转换为 DataSet。
这是我的功能:
public DataSet SelectQuery(String p_sSql)
{
DataSet ds = new DataSet();
try
{
OleDbCommand myOleDbCommand = conn.CreateCommand();
myOleDbCommand.CommandText = p_sSql.ToString();
OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();
myOleDbDataReader.Read();
//here I want to add the result to the DataSet ds ...
myOleDbDataReader.Close();
conn.Close();
return ds;
}
catch (System.Exception ex)
{
MessageBox.Show("Error: " + ex.ToString());
return null;
}
}