Esempio n. 1
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;
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 public void OpenTransaction(conn con)
 {
     if (con.connstr.State == ConnectionState.Closed)
         con.OpenDB();
     this.tran = con.connstr.BeginTransaction();
 }
Esempio n. 4
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;
         }
     }
 }