Ejemplo n.º 1
0
        public DataSet ExecuteDataSet(string sql, SqlParameter[] p)
        {
            DataSet ds;

            using (SqlConnection cnn = SqlServerPortabilidade.getInstance().getConnection())
            {
                SqlCommand cmd = new SqlCommand();
                cnn.Open();
                cmd.CommandText    = sql;
                cmd.CommandTimeout = 0;
                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.Connection     = cnn;
                if (p != null)
                {
                    for (int i = 0; i < p.Length; i++)
                    {
                        cmd.Parameters.Add(p[i]);
                    }
                }
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                ds = new DataSet();
                da.Fill(ds, sql);
                cmd.Dispose();
                cnn.Close();
                cnn.Dispose();
            }
            return(ds);
        }
Ejemplo n.º 2
0
        public SqlDataReader ExecuteReader(string sql, SqlParameter[] p)
        {
            SqlDataReader reader;

            using (SqlConnection cnn = SqlServerPortabilidade.getInstance().getConnection())
            {
                SqlCommand cmd = new SqlCommand();
                cnn.Open();
                cmd.CommandText    = sql;
                cmd.CommandTimeout = 0;
                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.Connection     = cnn;
                if (p != null)
                {
                    for (int i = 0; i < p.Length; i++)
                    {
                        cmd.Parameters.Add(p[i]);
                    }
                }
                reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                cmd.Dispose();
                cnn.Close();
                cnn.Dispose();
            }
            return(reader);
        }
Ejemplo n.º 3
0
        public int ExecuteNonQuery(string sql, SqlParameter[] p)
        {
            int retval;

            using (SqlConnection cnn = SqlServerPortabilidade.getInstance().getConnection())
            {
                SqlCommand cmd = new SqlCommand();
                cnn.Open();
                cmd.CommandText    = sql;
                cmd.CommandTimeout = 0;
                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.Connection     = cnn;
                if (p != null)
                {
                    for (int i = 0; i < p.Length; i++)
                    {
                        cmd.Parameters.Add(p[i]);
                    }
                }
                retval = cmd.ExecuteNonQuery();
                cmd.Dispose();
                cnn.Close();
                cnn.Dispose();
            }
            return(retval);
        }
 public static SqlServerPortabilidade getInstance()
 {
     if (instance == null)
     {
         instance = new SqlServerPortabilidade();
     }
     return(instance);
 }