コード例 #1
0
        public static DataSet SecureCreateDataset(string sqlString, DbSqlParameterCollection sqlParams)
        {
            DataSet    Secure = new DataSet();
            SqlCommand cmd    = (IsTransaction)?GetConnection.CreateCommand():GetNewConnection.CreateCommand();

            cmd.CommandText = sqlString;
            SqlDataAdapter SqlDataAdapter = new SqlDataAdapter(cmd);

            if (IsTransaction)
            {
                SqlDataAdapter.SelectCommand.Transaction = currentTransaction;
            }
            foreach (DbSqlParameter ss in sqlParams)
            {
                cmd.Parameters.Add(ss.Parameter);
            }
            try
            {
                if (cmd.Connection.State != ConnectionState.Open)
                {
                    cmd.Connection.Open();
                }
                if (currentTransaction != null)
                {
                    cmd.Transaction = currentTransaction;
                }
                SqlDataAdapter.Fill(Secure);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
            }
            return(Secure);
        }
コード例 #2
0
 public static DataSet SecureCreateDataset(string sqlstring, DbSqlParameterCollection sqlParams)
 {
     //DataSet Secure = new DataSet();
     using (SqlCommand cmd = (IsTransaction) ? GetConnection.CreateCommand() : GetNewConnection.CreateCommand())
     {
         cmd.CommandText = sqlstring;
         using (SqlDataAdapter SqlDataAdapter = new SqlDataAdapter(cmd))
         {
             if (IsTransaction)
             {
                 SqlDataAdapter.SelectCommand.Transaction = currentTransaction;
             }
             foreach (DbSqlParameter ss in sqlParams)
             {
                 cmd.Parameters.Add(ss.Parameter);
             }
             try
             {
                 if (currentTransaction != null)
                 {
                     cmd.Transaction = currentTransaction;
                 }
                 using (DataSet Secure = new DataSet())
                 {
                     try
                     {
                         SqlDataAdapter.Fill(Secure);
                         return(Secure);
                     }
                     catch (Exception ex)
                     {
                         LogFileWrite("Page Url:   " + HttpContext.Current.Request.Url + Environment.NewLine + "In Dal layer  (SecureCreateDataset) " + Environment.NewLine + "Error  : " + ex.Message);
                         throw;
                     }
                 }
             }
             catch (Exception ex)
             {
                 LogFileWrite("Page Url:   " + HttpContext.Current.Request.Url + Environment.NewLine + "Error  : " + ex.Message);
                 return(null);
             }
             finally
             {
                 cmd.Connection.Close();
                 closeconnection();
             }
             ;
         }
     }
 }