protected void Button4_Click(object sender, EventArgs e)//Add to favorites button { if (Label2.Text == "") { Label10.Text = ""; //Remove favorites message Label9.Text = "Search a company first to add it to favorites" + Request.Form["quantity"].ToString(); return; } else { //SqlConnection db = new SqlConnection(ConnectionString.ConnString); //db.Open(); //get the userID for a specified UserName //get the CompanyCode for a specified company //store the retrieved data into the Favorites table of the database /* * string addToFavorites = string.Format(@" * declare @UserID int * select @UserID = UserID from Users where UserName = '******' * insert into Favorites(UserID, CompanyCode) values (@UserID, '{1}') * ", Session["Username"].ToString(), Label2.Text); * * SqlCommand cmd = new SqlCommand(); * cmd.Connection = db; * cmd.CommandText = addToFavorites; * cmd.ExecuteNonQuery(); * db.Close(); */ Records.AddToFavorites(Session["Username"].ToString(), Label2.Text); Label9.Text = ""; //Remove all error messages Label10.Text = Label2.Text + " added to favorites"; } }