public static bool exebsql(string sql) { bool b = false; using (conn con = new conn()) { b = con.exebscalar(sql); return b; } }
//执行sql语句 //public int execsql(string cmdText,SqlParameter[] paras) //执行sql语句 //{ // int myop = 0; // if (connstr.State == ConnectionState.Closed) // OpenDB(); // using (SqlCommand cmd = new SqlCommand()) // { // cmd.Connection = connstr; // cmd.CommandText = cmdText; // cmd.CommandType = CommandType.StoredProcedure; // cmd.Parameters.AddRange(paras); // myop = cmd.ExecuteNonQuery(); // close(); // } // return myop; //} public static int execsql(string cmdText, SqlParameter[] paras) { int myop = 0; using (conn con = new conn()) { if (con.connstr.State == ConnectionState.Closed) con.OpenDB(); using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con.connstr; cmd.CommandText = cmdText; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddRange(paras); myop = cmd.ExecuteNonQuery(); con.close(); } } return myop; }
public void RollbackTran(conn con) { if (this.tran != null) this.tran.Rollback(); if (con.connstr.State == ConnectionState.Open) con.close(); }
public void OpenTransaction(conn con) { if (con.connstr.State == ConnectionState.Closed) con.OpenDB(); this.tran = con.connstr.BeginTransaction(); }
public DateTime getCurrentDate() { string date = string.Empty; using (conn con = new conn()) { date = con.exesscalar("select getdate()"); } return DateTime.Parse(date); }
public static string updatesvalue(string tablename, string ziduan, string tiaojian) { using (conn con = new conn()) { string s = con.exesscalar("update " + tablename + " set " + ziduan + " where " + tiaojian); return s; } }
//执行sql语句 public static void exesql(string sql) { using (conn con = new conn()) { con.execsql(sql); } }
//执行sql语句 public static ArrayList execsql(string cmdText, SqlParameter[] paras, params string[] outparams) { int outid = 0; ArrayList array = new ArrayList(); using (conn con = new conn()) { if (con.connstr.State == ConnectionState.Closed) con.OpenDB(); using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con.connstr; cmd.CommandText = cmdText; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddRange(paras); cmd.ExecuteNonQuery(); foreach (var item in outparams) { array.Add(cmd.Parameters[item].Value); } con.close(); } } return array; }
public static int getivalue(string tablename, string getziduan, string tiaojian) { using (conn con = new conn()) { int i = con.exeiscalar("select " + getziduan + " from " + tablename + " where " + tiaojian); return i; } }
public static DataTable getdatatable(string sql) { DataTable dt = new DataTable(); using (conn con = new conn()) { DataSet ds = con.dataset(sql); dt = ds.Tables[0]; return dt; } }
//返回DataSet对象 public static DataSet GetdatasetBySql(string sql) { using (conn con = new conn()) { if (con.connstr.State == ConnectionState.Closed) con.OpenDB(); using (SqlDataAdapter rs = new SqlDataAdapter()) { rs.SelectCommand = new SqlCommand(); rs.SelectCommand.Connection = con.connstr; rs.SelectCommand.CommandText = sql; rs.SelectCommand.CommandType = CommandType.Text; DataSet ds = new DataSet(); rs.Fill(ds); con.close(); return ds; } } }
public static int getcount(string tablename,string colName, string tiaojian) { using (conn con = new conn()) { int i = con.exeiscalar("select count(" + colName + ") from " + tablename + " where " + tiaojian); return i; } }
public static int getcount(string tablename) { using (conn con = new conn()) { int i = con.exeiscalar("select count(classid) from " + tablename); return i; } }
public static string exessql(string sql) { string s = ""; using (conn con = new conn()) { s = con.exesscalar(sql); return s; } }
public void SumitTran(conn con) { if (this.tran != null) this.tran.Commit(); if (con.connstr.State == ConnectionState.Open) con.close(); }
public static string getsvalue(string tablename, string getziduan, string tiaojian) { using (conn con = new conn()) { string s = con.exesscalar("select " + getziduan + " from " + tablename + " where " + tiaojian); return s; } }
public static int maxid(string tablename) { using (conn con = new conn()) { int i = con.exeiscalar("select max(id) from " + tablename); return i; } }
private DataTable[] GetData(string sqlstr) { DataSet ds = null; DataTable[] dtArray = null; using (conn con = new conn()) { ds = con.dataset(sqlstr); } if (ds != null) { dtArray = new DataTable[ds.Tables.Count]; int index = 0; totalCount = 1; foreach (DataTable dtitem in ds.Tables) { if (dtitem.Rows.Count > 0) { totalCount *= dtitem.Rows.Count; } dtArray[index++] = dtitem; } } return dtArray; }
//执行sql语句 public static int exeisql(string sql) { int i = 0; using (conn con = new conn()) { i = con.exeiscalar(sql); return i; } }