日期:2014-05-18 浏览次数:20948 次
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.Configuration; using System.Data; using System.Data.OracleClient; namespace Dal { public class DBHelper { //private static SqlConnection conn; private static OracleConnection conn; private static OracleCommand comm; /// <summary> /// 数据库连接串 /// </summary> static string str = "Data Source=库名;Persist Security Info=True;User ID=用户ID;Password=密码;Unicode=True"; // static string str =ConfigurationManager.ConnectionStrings["connstr"].ToString(); public static OracleConnection Conn() { if (conn == null) { conn = new OracleConnection(str); return conn; } if (conn.State == ConnectionState.Closed) { conn.Open(); return conn; } return conn; } public static int Excute(string sql, OracleParameter[] sp) { comm = new OracleCommand(sql, Conn()); if (sp != null) { foreach (OracleParameter op in sp) { comm.Parameters.Add(op); } } return comm.ExecuteNonQuery(); } public static DataSet getSet(string sql, OracleParameter[] sp) { DataSet ds = new DataSet(); comm = new OracleCommand(sql, Conn()); if (sp != null) { foreach (OracleParameter op in sp) { comm.Parameters.Add(op); } } OracleDataAdapter da = new OracleDataAdapter(comm); da.Fill(ds); return ds; } } }