예제 #1
0
 public static bool exebsql(string sql)
 {
     bool b = false;
     using (conn con = new conn())
     {
         b = con.exebscalar(sql);
         return b;
     }
 }
예제 #2
0
 //执行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;
 }
예제 #3
0
 public void RollbackTran(conn con)
 {
     if (this.tran != null) this.tran.Rollback();
     if (con.connstr.State == ConnectionState.Open)
         con.close();
 }
예제 #4
0
 public void OpenTransaction(conn con)
 {
     if (con.connstr.State == ConnectionState.Closed)
         con.OpenDB();
     this.tran = con.connstr.BeginTransaction();
 }
예제 #5
0
 public DateTime getCurrentDate()
 {
     string date = string.Empty;
     using (conn con = new conn())
     {
         date = con.exesscalar("select getdate()");
     }
     return DateTime.Parse(date);
 }
예제 #6
0
 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;
     }
 }
예제 #7
0
 //执行sql语句
 public static void exesql(string sql)
 {
     using (conn con = new conn())
     {
         con.execsql(sql);
     }
 }
예제 #8
0
 //执行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;
 }
예제 #9
0
 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;
     }
 }
예제 #10
0
 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;
     }
 }
예제 #11
0
 //返回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;
         }
     }
 }
예제 #12
0
 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;
     }
 }
예제 #13
0
 public static int getcount(string tablename)
 {
     using (conn con = new conn())
     {
         int i = con.exeiscalar("select count(classid) from " + tablename);
         return i;
     }
 }
예제 #14
0
 public static string exessql(string sql)
 {
     string s = "";
     using (conn con = new conn())
     {
         s = con.exesscalar(sql);
         return s;
     }
 }
예제 #15
0
 public void SumitTran(conn con)
 {
     if (this.tran != null) this.tran.Commit();
     if (con.connstr.State == ConnectionState.Open)
         con.close();
 }
예제 #16
0
 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;
     }
 }
예제 #17
0
 public static int maxid(string tablename)
 {
     using (conn con = new conn())
     {
         int i = con.exeiscalar("select max(id) from " + tablename);
         return i;
     }
 }
예제 #18
0
 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;
 }
예제 #19
0
 //执行sql语句
 public static int exeisql(string sql)
 {
     int i = 0;
     using (conn con = new conn())
     {
         i = con.exeiscalar(sql);
         return i;
     }
 }