Ejemplo n.º 1
0
        public static int InsertGuest(GuestCS sr)
        {
            int new_id = 0;
            //declare return variable

            //connection object -> ConfigurationManager namespace
            //access to web.config -> connection strings & key values
            SqlConnection cn = new SqlConnection(
                ConfigurationManager.ConnectionStrings["SE256_CorwinConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("guests_insert", cn);

            // Mark the Command -> Stored Procedure
            cmd.CommandType = CommandType.StoredProcedure;

            // Add Parameters -> Stored Procedure
            cmd.Parameters.Add(
                "@new_id", SqlDbType.Int).Direction = ParameterDirection.Output;
            cmd.Parameters.Add(
                "@guest_email", SqlDbType.VarChar).Value = sr.Guest_Email;
            cmd.Parameters.Add(
                "@guest_first", SqlDbType.VarChar).Value = sr.Guest_First;
            cmd.Parameters.Add(
                "@guest_last", SqlDbType.VarChar).Value = sr.Guest_Last;
            cmd.Parameters.Add(
                "@guest_salt", SqlDbType.VarChar).Value = sr.Guest_Salt;
            cmd.Parameters.Add(
                "@guest_pwd", SqlDbType.VarChar).Value = sr.Guest_Pwd;
            cmd.Parameters.Add(
                "@guest_phone", SqlDbType.VarChar).Value = sr.Guest_Phone;


            // Open database connection -> execute command
            try
            {
                cn.Open();
                //execute -> stored procedure
                cmd.ExecuteNonQuery();
                new_id = Convert.ToInt32(cmd.Parameters["@new_id"].Value);
            }
            catch (Exception exc)
            {
                //error -> notify user
                exc.ToString();
            }
            finally
            {
                cn.Close();
            }
            return(new_id);
        }
Ejemplo n.º 2
0
        public static bool UpdateGuest(GuestCS sr)
        {
            //declare return variable
            bool blnSuccess = false;
            //connection object -> ConfigurationManager namespace
            //access web.config setting -> connection strings & key values
            SqlConnection cn = new SqlConnection(
                ConfigurationManager.ConnectionStrings["SE256_CorwinConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("guests_update", cn);

            // Mark the Command -> Stored Procedure
            cmd.CommandType = CommandType.StoredProcedure;

            // Add Parameters -> Stored Procedure
            cmd.Parameters.Add(
                "@guest_id", SqlDbType.Int).Value = sr.Guest_ID;
            cmd.Parameters.Add(
                "@guest_email", SqlDbType.VarChar).Value = sr.Guest_Email;
            cmd.Parameters.Add(
                "@guest_first", SqlDbType.VarChar).Value = sr.Guest_First;
            cmd.Parameters.Add(
                "@guest_last", SqlDbType.VarChar).Value = sr.Guest_Last;
            cmd.Parameters.Add(
                "@guest_salt", SqlDbType.VarChar).Value = sr.Guest_Salt;
            cmd.Parameters.Add(
                "@guest_pwd", SqlDbType.VarChar).Value = sr.Guest_Pwd;
            cmd.Parameters.Add(
                "@guest_phone", SqlDbType.VarChar).Value = sr.Guest_Phone;


            // Open database connection -> execute command
            try
            {
                cn.Open();
                cmd.ExecuteNonQuery();
                blnSuccess = true;
            }
            catch (Exception exc)
            {
                //error -> notify user
                exc.ToString();
                blnSuccess = false;
            }
            finally
            {
                cn.Close();
            }
            return(blnSuccess);
        }