Click here to Skip to main content
16,004,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
After searching stackoverflow for hours I was able to find a great answer to an issue I was having. Updating existing entries in an access database through the datagridview. Using what I learned there I was able to commit an update to database successfully. However I have found issue. I can only make one update per application session. After I make one successfully, all subsequent updates to not save to database. I am hoping someone on the site can take a look at my code and help pin point where my issue is. I have looked at it for a couple days to no avail.

//Code for editing

C#
private void AssetForm_Load(object sender, EventArgs e)
        {
            //ACCESSORIES DATA GRID VIEW
            this.accessoriesTableAdapter.Fill(this.fAMDatabaseDataSet.Accessories);
            con.Open();
            string accCommandText = "SELECT * from Accessories";
            accAdapter = new OleDbDataAdapter(accCommandText, con);
            OleDbCommandBuilder accCB = new OleDbCommandBuilder(accAdapter);
            accView.AutoGenerateColumns = true;
            accDT = new System.Data.DataTable();
            accAdapter.Fill(accDT);
            BindingSource accBS = new BindingSource();
            accBS.DataSource = accDT;
            accView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
            accView.DataSource = accBS;
            con.Close();
        }

//Button that commits back to database

C#
private void accEditButton_Click(object sender, EventArgs e)
        {
            accAdapter.Update(accDT);
            accView.Refresh();
            MessageBox.Show("Asset Updated Successfully.");
        }
Posted

1 solution

Please see this Example, This will help you.

Using the DataGrid Control[^]
 
Share this answer
 
Comments
Member 10991115 8-Aug-14 9:30am    
Does this also work for DataGridView with WinForms? This code is not making any updates. When I modify a cell in the datagridview it simply says "Nothing to Save"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900