Beispiel #1
0
        public AccountsDAL retrieveByAccId(int accId)
        {
            AccountsDAL p = null;
            string      strCommandText = "SELECT * FROM Accounts where AccountID = @accId";
            string      uName, pwd, fullNm, mobileNo, emailAdd, add, accountType;
            // bool accIdConfirmed;

            SqlConnection myConnection = new SqlConnection(strConnectionString);
            SqlCommand    cmd          = new SqlCommand(strCommandText, myConnection);

            cmd.Parameters.AddWithValue("@accId", accId);


            try
            {
                myConnection.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    accId       = (int)reader["AccountID"];
                    uName       = reader["userName"].ToString();
                    pwd         = reader["password"].ToString();
                    fullNm      = reader["fullName"].ToString();
                    mobileNo    = reader["mobile"].ToString();
                    emailAdd    = reader["email"].ToString();
                    add         = reader["address"].ToString();
                    accountType = reader["accType"].ToString();

                    p             = new AccountsDAL(accId, uName, pwd, fullNm, mobileNo, emailAdd, add, accountType);
                    p.uName       = uName;
                    p.fullNm      = fullNm;
                    p.accountType = accountType;
                }
            }
            catch (Exception ex)
            {
                //throw new Exception(ex.ToString());
                p = null;
            }
            finally { myConnection.Close(); }
            return(p);
        }
Beispiel #2
0
        public AccountsDAL retrieveUser(string uName, string pwd)
        {
            AccountsDAL p = null;
            string      strCommandText = "SELECT * FROM Accounts WHERE userName = @uName AND password = @pwd";

            string fullNm, mobileNo, emailAdd, add, accountType;
            int    accId;

            SqlConnection myConnection = new SqlConnection(strConnectionString);
            SqlCommand    cmd          = new SqlCommand(strCommandText, myConnection);

            cmd.Parameters.AddWithValue("@uName", uName);
            cmd.Parameters.AddWithValue("@pwd", pwd);


            try
            {
                myConnection.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    accId       = (int)reader["AccountID"];
                    uName       = reader["userName"].ToString();
                    pwd         = reader["password"].ToString();
                    fullNm      = reader["fullName"].ToString();
                    mobileNo    = reader["mobile"].ToString();
                    emailAdd    = reader["email"].ToString();
                    add         = reader["address"].ToString();
                    accountType = reader["accType"].ToString();

                    p = new AccountsDAL(accId, uName, pwd, fullNm, mobileNo, emailAdd, add, accountType);
                }
            }
            catch (Exception ex)
            {
                p = null;
            }
            finally { myConnection.Close(); }
            return(p);
        }