My Database is not getting Update

CWareIndia
CWareIndia used Ask the Experts™
on
Hi,
    I am creating windows application using MS Access database, and dot net 3.5. I am trying to delete rows from database using dataset. My problem is that when i use adapter.update and dataset.commitchanges method ,row from datagrid deleted but my database remains the same, no row is deleting from database. Please help me.....................
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
You need to use a Commnd builder. Which needs to be instansiated at the same time as the adaptor is.

Dim oCBuilder as OleDb.OleDbCommandBuilder

'... Create Adaptor'
oCBuilder = New OleDb.OleDbCommandBuilder(oAdaptor)
oAdaptor.Fill(oDataSet)
'... Do whatever'
'... Then when it comes to committing the changes'
oCBuilder.GetDeleteCommand()
'.... Theres also a GetUpdateCommand() [For amending existing fields]'
'.... And GetInsertCommand() [For creating adding new rows]'
oAdaptor.Update(oDataSet)

Open in new window

Author

Commented:
My code is like that please tell me what is wrong in it.
DataGridView.Rows.RemoveAt(DataGridView.CurrentRow.Index)   OleDbCommandBuilder.GetUpdateCommand();
   OleDbDataAdapter.Update(DataTable);
            DataGridView..Update();
           DataTable.AcceptChanges();
   
 My Datagrid update but changes are not reflecting in database.

Commented:
GetDeleteCommand() - will delete specified rows
GetUpdateCommand() - will only alter values that are in existing fields.
GetInsertCommand() - will insert new rows.

You need to use GetDeleteCommand() in this instance.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
GetDeleteCommand is also not working.
I am also not able to insert new record in database . When i connect to sql server and use same code, changes reflect in database. What could be the problem.

Commented:
Can you show me the code your using, with the GetDeleteCommand implemented.
nishant joshiTechnology Development Consultant

Commented:
dataset.commitchanges method should be first then update.
Hi , i got my solution.actually each time when i built the project my database copy in to bin folder, and all changes were lost. actually when i update records, it updated from bin folder database and when i built the project bin database replace with actual database and changes were lost. When i set  'copy to output directory'='Copy when newer' of database property.My problem solved.

Author

Commented:
closed.

Author

Commented:
i got my solution.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial