Link to home
Start Free TrialLog in
Avatar of CWareIndia
CWareIndiaFlag for India

asked on

My Database is not getting Update

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.....................
Avatar of gman84
gman84
Flag of United Kingdom of Great Britain and Northern Ireland image

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

Avatar of CWareIndia

ASKER

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.
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.
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.
Can you show me the code your using, with the GetDeleteCommand implemented.
Avatar of nishant joshi
dataset.commitchanges method should be first then update.
ASKER CERTIFIED SOLUTION
Avatar of CWareIndia
CWareIndia
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
closed.
i got my solution.