Example #1
0
        private DataRow ReturnDataRow(string SelectQuery, CommandType cmdType)
        {
            DataTable     dt;
            SqlConnection conn = null;

            try
            {
                SqlCmd = new SqlCommand();
                dt     = new DataTable();
                conn   = ClsConnection.OpenConnectiion();

                SqlCmd.Connection  = conn;
                SqlCmd.CommandText = SelectQuery;
                SqlCmd.CommandType = cmdType;
                SqlAdp             = new SqlDataAdapter(SqlCmd);
                SqlAdp.Fill(dt);

                return(dt.Rows[0]);
            }

            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (conn != null && conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                conn.Dispose();
                SqlCmd = null;
            }
        }
Example #2
0
        private DataRow ReturnDataRow(string SelectQuery, SqlParameter[] _SqlParameter, CommandType cmdType)
        {
            DataTable     dt;
            SqlConnection conn = null;

            try
            {
                SqlCmd = new SqlCommand();
                dt     = new DataTable();
                conn   = ClsConnection.OpenConnectiion();

                SqlCmd.Connection     = conn;
                SqlCmd.CommandText    = SelectQuery;
                SqlCmd.CommandType    = cmdType;
                SqlCmd.CommandTimeout = 60;
                for (int i = 0; i < _SqlParameter.Length; i++)
                {
                    SqlCmd.Parameters.Add(_SqlParameter[i]);
                }

                SqlAdp = new SqlDataAdapter(SqlCmd);
                SqlAdp.Fill(dt);
                if (dt.Rows.Count == 0)
                {
                    return(null);
                }

                return(dt.Rows[0]);
            }

            catch (Exception ex)
            {
                throw ex;
            }

            finally
            {
                if (conn != null && conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                conn.Dispose();
                SqlCmd = null;
            }
        }
Example #3
0
        public int Executes(string cmdText, SqlParameter[] _SqlParameter, CommandType cmdType = CommandType.StoredProcedure)
        {
            int NoOfRowsEffected = 0;

            SqlCmd = new SqlCommand();
            SqlConnection conn = null;

            try
            {
                conn = ClsConnection.OpenConnectiion();
                SqlCmd.Connection     = conn;
                SqlCmd.CommandType    = cmdType;
                SqlCmd.CommandText    = cmdText;
                SqlCmd.CommandTimeout = 600;
                for (int i = 0; i < _SqlParameter.Length; i++)
                {
                    SqlCmd.Parameters.Add(_SqlParameter[i]);
                }
                NoOfRowsEffected = SqlCmd.ExecuteNonQuery();
                return(NoOfRowsEffected);
            }

            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (conn != null && conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                conn.Dispose();
                SqlCmd = null;
            }
        }