Beispiel #1
0
        protected static object ExecCmdScalar(string ConnStr, string commandText, CommandType commandType, SqlParameterList parameters)
        {
            SqlConnection conn = new SqlConnection(ConnStr);
            SqlCommand    cmd  = new SqlCommand(commandText, conn);

            cmd.CommandTimeout = 80000;
            try
            {
                cmd.CommandType = commandType;

                if (parameters != null)
                {
                    foreach (SqlParameter parm in parameters)
                    {
                        cmd.Parameters.Add(parm);
                    }
                }

                conn.Open();
                return(cmd.ExecuteScalar());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                    conn.Dispose();
                    cmd.Dispose();
                }
            }
        }
Beispiel #2
0
        protected static DataSet ExecCmdDataSet(string ConnStr, string commandText, CommandType commandType, SqlParameterList parameters)
        {
            DataSet        ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter();

            SqlConnection conn = new SqlConnection(ConnStr);
            SqlCommand    cmd  = new SqlCommand(commandText, conn);

            cmd.CommandTimeout = 0;
            try
            {
                cmd.CommandType = commandType;

                if (parameters != null)
                {
                    foreach (SqlParameter parm in parameters)
                    {
                        cmd.Parameters.Add(parm);
                    }
                }

                conn.Open();
                da = new SqlDataAdapter(cmd);
                da.Fill(ds);
                return(ds);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                    conn.Dispose();
                    cmd.Dispose();
                    da.Dispose();
                }
            }
        }