edit this code so that it contains a second dataviewgrid which contains displays this…
- User
edit this code so that it contains a second dataviewgrid which contains displays this time a table from the SAME databse called tbl_user and contains columns username|password|fullname|email|address
make sure it has the exact same functions as the first dataview grid and it also gives the same functions to 2 new buttons (button2 and button3) which as are equivlant to save button and button1 for the first dataview grid
in conclusion i want to duplicate the dataviewgrid and its 2 buttons but this time for another table within the database code to be rewritten: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO;
namespace ApplianceRental { public partial class AdminDashboardForm : Form { OleDbDataAdapter sda; OleDbCommandBuilder scb; DataTable dt; OleDbConnection con; string connectionString = $@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source = { Path.Combine(Application.StartupPath, "db_users.mdb") }";
public AdminDashboardForm() { InitializeComponent(); con = new OleDbConnection(connectionString); } private void AdminDashboardForm_Load(object sender, EventArgs e) { } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { // Code logic for the event handler } private void saveButton_Click(object sender, EventArgs e) { using (OleDbCommand insertCommand = new OleDbCommand("INSERT INTO ApplianceDBLIST ([Appliance], [Power Usage], [Typical Usage], [Estimated Annual Costs]) VALUES (?, ?, ?, ?)", con), updateCommand = new OleDbCommand("UPDATE ApplianceDBLIST SET [Appliance]=?, [Power Usage]=?, [Typical Usage]=?, [Estimated Annual Costs]=? WHERE ID=?", con), deleteCommand = new OleDbCommand("DELETE FROM ApplianceDBLIST WHERE ID=?", con)) { sda.InsertCommand = insertCommand; insertCommand.Parameters.Add("@Appliance", OleDbType.VarWChar, 0, "Appliance"); insertCommand.Parameters.Add("@Power_Usage", OleDbType.VarWChar, 0, "Power Usage"); insertCommand.Parameters.Add("@Typical_Usage", OleDbType.VarWChar, 0, "Typical Usage"); insertCommand.Parameters.Add("@Estimated_annual_costs", OleDbType.VarWChar, 0, "Estimated Annual Costs"); sda.UpdateCommand = updateCommand; updateCommand.Parameters.Add("@Appliance", OleDbType.VarWChar, 0, "Appliance"); updateCommand.Parameters.Add("@Power_Usage", OleDbType.VarWChar, 0, "Power Usage"); updateCommand.Parameters.Add("@Typical_Usage", OleDbType.VarWChar, 0, "Typical Usage"); updateCommand.Parameters.Add("@Estimated_annual_costs", OleDbType.VarWChar, 0, "Estimated Annual Costs"); updateCommand.Parameters.Add("@ID", OleDbType.Integer, 0, "ID"); updateCommand.UpdatedRowSource = UpdateRowSource.None; sda.DeleteCommand = deleteCommand; deleteCommand.Parameters.Add("@ID", OleDbType.Integer, 0, "ID"); deleteCommand.UpdatedRowSource = UpdateRowSource.None; con.Open(); sda.Update(dt); con.Close(); // Refresh the data after updating, to display updated data in DataGridView dt.Clear(); sda.Fill(dt); } } private void button1_Click(object sender, EventArgs e) { string query = "SELECT * FROM ApplianceDBLIST"; sda = new OleDbDataAdapter(query, con); OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(sda); dt = new DataTable(); sda.Fill(dt); dataGridView1.DataSource = dt; } private void label7_Click(object sender, EventArgs e) { } private void label1_Click(object sender, EventArgs e) { } } - Assistant