public static object ExecuteScalar(CommandType cmdType, string cmdText, params SqlParameter[] cmdParms) { ISession session = SessionFactory.OpenSession("WC.Model"); object result; using (SqlConnection sqlConnection = (SqlConnection)session.Connection) { try { SqlCommand sqlCommand = new SqlCommand(); MsSqlOperate.PrepareCommand(sqlCommand, sqlConnection, null, cmdType, cmdText, cmdParms); object obj = sqlCommand.ExecuteScalar(); sqlCommand.Parameters.Clear(); result = obj; } catch (SqlException ex) { throw ex; } finally { session.Close(); session.Dispose(); } } return(result); }
public static int ExecuteNonQuery(CommandType cmdType, string cmdText, params SqlParameter[] cmdParms) { ISession session = SessionFactory.OpenSession("WC.Model"); int result; using (SqlConnection sqlConnection = (SqlConnection)session.Connection) // using (SqlConnection sqlConnection = (SqlConnection)session.get_Connection()) { try { SqlCommand sqlCommand = new SqlCommand(); MsSqlOperate.PrepareCommand(sqlCommand, sqlConnection, null, cmdType, cmdText, cmdParms); int num = sqlCommand.ExecuteNonQuery(); sqlCommand.Parameters.Clear(); result = num; } catch (Exception ex) { throw ex; } finally { session.Close(); session.Dispose(); } } return(result); }
public static DataSet ExecuteDataset(CommandType cmdType, string cmdText, params SqlParameter[] cmdParms) { ISession session = SessionFactory.OpenSession("WC.Model"); DataSet result; using (SqlConnection sqlConnection = (SqlConnection)session.Connection) { try { SqlCommand sqlCommand = new SqlCommand(); MsSqlOperate.PrepareCommand(sqlCommand, sqlConnection, null, cmdType, cmdText, cmdParms); using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand)) { DataSet dataSet = new DataSet(); sqlDataAdapter.Fill(dataSet); sqlCommand.Parameters.Clear(); result = dataSet; } } catch (SqlException ex) { throw ex; } finally { session.Close(); session.Dispose(); } } return(result); }
public static SqlDataReader ExecuteReader(CommandType cmdType, string cmdText, params SqlParameter[] cmdParms) { ISession session = SessionFactory.OpenSession("WC.Model"); SqlConnection conn = (SqlConnection)session.Connection; SqlDataReader result; try { SqlCommand sqlCommand = new SqlCommand(); MsSqlOperate.PrepareCommand(sqlCommand, conn, null, cmdType, cmdText, cmdParms); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection); sqlCommand.Parameters.Clear(); result = sqlDataReader; } catch (SqlException ex) { session.Close(); session.Dispose(); throw ex; } return(result); }
public static int ExecuteNonQuery(SqlTransaction trans, SqlConnection conn, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms) { int result; try { SqlCommand sqlCommand = new SqlCommand(); MsSqlOperate.PrepareCommand(sqlCommand, conn, trans, cmdType, cmdText, cmdParms); int num = sqlCommand.ExecuteNonQuery(); sqlCommand.Parameters.Clear(); result = num; } catch (SqlException ex) { throw ex; } finally { conn.Close(); } return(result); }