两种获取connectionString的方式案例详解
using System.Data;using Oracle.DataAccess.Client; //注意添加Oracle的引用 ;SqlServer自带 DataSet dataSet = new DataSet();List
using (OracleConnection oracleConnection = new OracleConnection(connectionString))
{
oracleConnection.Open();
OracleCommand selectCommand = new OracleCommand(sql, oracleConnection);
OracleDataAdapter oracleDataAdapter = new OracleDataAdapter(selectCommand);
oracleDataAdapter.Fill(dataSet);
}
if (dataSet.Tables.Count > 0 && dataSet.Tables[0] != null && dataSet.Tables[0].Rows.Count > 0)
{ //连接成功且返回数据
foreach (DataRow dr in dataSet.Tables[0].Rows)
{
listzh.Add(new ZHInfo { Code = dr["Code"].ToString(), Name = dr["Name"].ToString(), PublicNumber = dr["Phone_Number"].ToString() });
}
}