// TODO: add a respondent public static bool AddRespondent(Respondent respondent) { try { using (SqlConnection connection = BicycleStoreCorpDB.GetConnection()) { string queryString = "INSERT INTO Respondents (FirstName, LastName, EmailAddress, AddressLine1, AddressLine2, City, StateAbbr, ZipCode, LastSurvey)" + " VALUES (@FirstName, @LastName, @EmailAddress, @AddressLine1, @AddressLine2, @City, @StateAbbr, @ZipCode, GETDATE())"; SqlCommand cmd = new SqlCommand(queryString, connection); cmd.Parameters.AddWithValue("@FirstName", respondent.FirstName); cmd.Parameters.AddWithValue("@LastName", respondent.LastName); cmd.Parameters.AddWithValue("@EmailAddress", respondent.EmailAddress); cmd.Parameters.AddWithValue("@AddressLine1", respondent.AddressLine1); cmd.Parameters.AddWithValue("@AddressLine2", respondent.AddressLine2); cmd.Parameters.AddWithValue("@City", respondent.City); cmd.Parameters.AddWithValue("@StateAbbr", respondent.StateAbbr); cmd.Parameters.AddWithValue("@ZipCode", respondent.ZipCode); connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } } catch (Exception ex) { MessageBox.Show("Error: " + ex.ToString()); return(false); } return(true); // throw new NotImplementedException(); }
private void PutRespondent(Respondent respondent) { respondent.EmailAddress = txtEmailAddress.Text; respondent.FirstName = txtFirstName.Text; respondent.LastName = txtLastName.Text; respondent.AddressLine1 = txtAddressLine1.Text; respondent.AddressLine2 = txtAddressLine2.Text; respondent.City = txtCity.Text; respondent.StateAbbr = txtStateAbbr.Text; respondent.ZipCode = txtZip.Text; }
private void GetRespondent(string email) { try { respondent = RespondentsDB.GetRespondent(email); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
// get the respondent information public static Respondent GetRespondent(string email) { Respondent matchingRespondent = new Respondent(); try { using (SqlConnection connection = BicycleStoreCorpDB.GetConnection()) { string qryString = "SELECT * FROM Respondents WHERE EmailAddress = @Email"; SqlCommand cmd = new SqlCommand(qryString, connection); cmd.Parameters.AddWithValue("@Email", email); connection.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { if (email.Equals(reader["EmailAddress"].ToString())) { matchingRespondent.RespondentID = Convert.ToInt32(reader["RespondentID"]); matchingRespondent.FirstName = reader["FirstName"].ToString(); matchingRespondent.LastName = reader["LastName"].ToString(); matchingRespondent.EmailAddress = reader["EmailAddress"].ToString(); matchingRespondent.AddressLine1 = reader["AddressLine1"].ToString(); matchingRespondent.AddressLine2 = reader["AddressLine2"].ToString(); matchingRespondent.City = reader["City"].ToString(); matchingRespondent.StateAbbr = reader["StateAbbr"].ToString(); matchingRespondent.ZipCode = reader["ZipCode"].ToString(); matchingRespondent.LastSurvey = (DateTime)reader["LastSurvey"]; } else { throw new DataException("Unexpected respondent returned."); } // connection.Close(); } } } } catch (Exception ex) { MessageBox.Show("Error: " + ex.ToString()); } return(matchingRespondent); }