public class OracleHelper
{
public static readonly string ConnString = "Data Source=DataBase;Persist Security Info=True;User ID=UserName;Password=Password;Unicode=True";
/// <summary>
/// 执行SQL增,删、改方法
/// </summary>
/// <param name="sqlText">sql语句</param>
/// <param name="param">参数</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(string sqlText,params OracleParameter[]param)
{
int result = 0;
using (OracleConnection conn = new OracleConnection(ConnString))
{
OracleCommand cmd = new OracleCommand(sqlText,conn);
if (param != null)
cmd.Parameters.AddRange(param);
conn.Open();
result = cmd.ExecuteNonQuery();
}
return result;
}
/// <summary>
/// 执行SQL语句读取数据集方法
/// </summary>
/// <param name="sqlText">SQL语句</param>
/// <param name="param">参数</param>
/// <returns>数据集</returns>
public static DataTable ExecuteReader(string sqlText,params OracleParameter[]param)
{
DataTable dt = new DataTable();
using (OracleConnection conn = new OracleConnection(ConnString))
{
OracleCommand cmd = new OracleCommand(sqlText,conn);
if (param != null)
cmd.Parameters.AddRange(param);
OracleDataAdapter da = new OracleDataAdapter(cmd);
da.Fill(dt);
}
return dt;
}
/// <summary>
/// 返回总记录数
/// </summary>
/// <param name="sqlText"></param>
/// <param name="param"></param>
/// <returns></returns>
public static int ExecuteScalar(string sqlText, params OracleParameter[] param)
{
int result = 0;
using (OracleConnection conn = new OracleConnection(ConnString))
{
OracleCommand cmd = new OracleCommand(sqlText,conn);
if (param != null)
cmd.Parameters.AddRange(param);
conn.Open();
result = Convert.ToInt32( cmd.ExecuteScalar());
}
return result;
}
}
标签:OracleCommand,数据库,cmd,param,cs,result,Oracle,new,conn From: https://www.cnblogs.com/jianhua-li/p/17218274.html