public void Add(Enterprises customer) { try { using (var conn = GetConnection()) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "INSERT INTO Enterprises(Representative, Phone, Note, Address, Email, NameEnterprise) VALUES(@Representative, @Phone, @Note, @Address, @Email, @NameEnterprise)"; //cmd.Parameters.AddWithValue("@IDEnterprise", customer.IDEnterprise); cmd.Parameters.AddWithValue("@Address", customer.Address); cmd.Parameters.AddWithValue("@Email", customer.Email); cmd.Parameters.AddWithValue("@NameEnterprise", customer.NameEnterprise); cmd.Parameters.AddWithValue("@Note", customer.Note); cmd.Parameters.AddWithValue("@Phone", customer.Phone); cmd.Parameters.AddWithValue("@Representative", customer.Representative); cmd.ExecuteNonQuery(); } } } catch (Exception exc) { MessageBox.Show(exc.Message, "Ошибка"); } }
public void Update(Enterprises customer) { try { using (var conn = GetConnection()) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "UPDATE Enterprises SET Note=@Note, Phone=@Phone, Representative=@Representative, Address = @Address, Email=@Email, NameEnterprise=@NameEnterprise WHERE IDEnterprise = @ID1"; cmd.Parameters.AddWithValue("@ID1", customer.IDEnterprise); cmd.Parameters.AddWithValue("@Address", customer.Address); cmd.Parameters.AddWithValue("@Email", customer.Email); cmd.Parameters.AddWithValue("@NameEnterprise", customer.NameEnterprise); cmd.Parameters.AddWithValue("@Note", customer.Note); cmd.Parameters.AddWithValue("@Phone", customer.Phone); cmd.Parameters.AddWithValue("@Representative", customer.Representative); cmd.ExecuteNonQuery(); } } } catch (Exception exc) { MessageBox.Show(exc.Message, "Ошибка"); } }
private static Enterprises LoadEnterprise(SqlDataReader reader) { Enterprises enterprise = new Enterprises(); try { enterprise.Address = reader.GetString(reader.GetOrdinal("Address")); enterprise.Email = reader.GetString(reader.GetOrdinal("Email")); enterprise.Note = reader.GetString(reader.GetOrdinal("Note")); enterprise.IDEnterprise = reader.GetInt32(reader.GetOrdinal("IDEnterprise")); enterprise.NameEnterprise = reader.GetString(reader.GetOrdinal("NameEnterprise")); enterprise.Phone = reader.GetDouble(reader.GetOrdinal("Phone")); enterprise.Representative = reader.GetString(reader.GetOrdinal("Representative")); } catch (Exception exc) { MessageBox.Show(exc.Message, "Ошибка"); } return(enterprise); }