protected void btn_guardar_Click(object sender, EventArgs e) { UserBusiness ub = new UserBusiness(); User u = new User(txb_name.Text,txb_email.Text,txb_carne.Text,txb_password.Text); ub.Insert(u); }
public void Insert(User user) { try { SqlConnection con = DataBaseConnection("open"); SqlCommand sqlcommand; string databaseCommand = " INSERT INTO [dbo].[User] (name,email,carne,password)values (" + "'" + user.Name + "'" + "," + "'" + user.Email + "'" + "," + "'" + user.Carne + "'" + "," + "'" + user.Password + "'" + ")"; sqlcommand = new SqlCommand(databaseCommand, con); sqlcommand.ExecuteNonQuery(); sqlcommand.Dispose(); DataBaseConnection("close"); } catch (SqlException sqlException) { Console.WriteLine("Database error:" + sqlException.ToString()); } }
public void Update(User user) { userData.Update(user); }
public void Insert(User user) { userData.Insert(user); }
public void Update(User user) { SqlConnection con = DataBaseConnection("open"); try { SqlCommand cmdIns = new SqlCommand("UPDATE user SET name=@name ,email=@email,carne=@carne,password=@password", con); cmdIns.Parameters.Add("@name", user.Name); cmdIns.Parameters.Add("@email", user.Email); cmdIns.Parameters.Add("@carne", user.Carne); cmdIns.Parameters.Add("@password", user.Password); cmdIns.ExecuteNonQuery(); cmdIns.Dispose(); cmdIns = null; } catch (SqlException ex) { throw new Exception(ex.ToString(), ex); } finally { DataBaseConnection("close"); } }