First i'll explain my program a bit.

Im writing a Windows based app. In the main form, i have a DataGridView which binded to a DataSet. When i double-click the RowHeader, a detailed view of the selected customer will pop-up. So i can make changes to the customer details, and when i press save, it changes the value in the datagridview of the main form manually, like this customerGridView["custNameDataGridViewTextBoxColumn", customerGridView.CurrentRow.Index].Value = customerDlg.txtName.Text; After that it'll fire the DataAdapter.Update() method. ShugahDA.Update(shugahCustomerDS); I've tried many ways, using the updateCommand, parameter method, and also the Updatecommand with the hardcoded SQL string method. But seems like the record is still not being updated.

I started to think that by manually change data like customerGridView["custNameDataGridViewTextBoxColumn", customerGridView.CurrentRow.Index].Value = customerDlg.txtName.Text; doesn't make the DataAdapter.Update() method to do anything (it thinks that the dataRow not changing) .

Can somebody help me with this?


Below is my codes for declaring UpdateCommand and the parameters

this.oleDbUpdateCommand1.CommandText = "UPDATE       Customer\r\nSET                CustName = ?\r\nWHERE        (CustID = ?)" +
                "";
            this.oleDbUpdateCommand1.Connection = this.oleDbConnection1;
            this.oleDbUpdateCommand1.Parameters.AddRange(new System.Data.OleDb.OleDbParameter[] {
            new System.Data.OleDb.OleDbParameter("CustName", System.Data.OleDb.OleDbType.VarChar, 255, "CustName"),
            new System.Data.OleDb.OleDbParameter("Original_CustID", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((byte)(0)), ((byte)(0)), "CustID", System.Data.DataRowVersion.Original, null)});

this.ShugahDA.UpdateCommand = this.oleDbUpdateCommand1;

Thanks in advance!

Recommended Answers

All 6 Replies

Hello, Ichibang.

Some time ago I had similar weird problem. Take a look, maybe this can help you to solve yours: Problem updating Database using typed dataset

P.S. I suppose there's a better way to fix that. But I couldn't find it.

After that it'll fire the DataAdapter.Update() method.
ShugahDA.Update(shugahCustomerDS)

Are you using Binding source?

this.oleDbUpdateCommand1.CommandText = "UPDATE Customer\r\nSET CustName = ?\r\nWHERE (CustID = ?)" + "";
this.ShugahDA.UpdateCommand = this.oleDbUpdateCommand1;

That is not valid commandText, no \r\n should exist
it should be

this.oleDbUpdateCommand1.CommandText = "UPDATE Customer SET CustName = ? WHERE (CustID = ?)"  

in line 8 which is the last line of your code, you are setting the updatecommand to the "ShugahDA" Data Adapter, that will not fire the update. Are you doing it else where?

Hi Samir

The commandText was generated by VS itself i don't know why it append \r\n in it, anyway i've changed it (but still is not working)

And yeah, i have a line ShugahDA.Update(shugahCustomerDS); (i assume that this will update the database)


And to add some more doubt to myself, im following example in the book Visual C#.Net Developer's Handbook written by Mueller, Chapter 11, OLEDB example. I compile the code and run it. It seems that the application too can't make changes to the database.

What went wrong?? Issit because of my MS Access 2007 that uses Microsoft.ACE.OLEDB.12.0 as provider? (i don't have the problem of Microsoft.ACE.OLEDB.12.0 provider is not registered)

Hello Ichibang

I had struggled with this issue for a while but finally I made it, here how things work.

First open the DataSet in the designer, click on the table you are working on, click on the TableAdapter and check if it has Update command, check the commandText and if the Parameter is correct.

if you are using BindingSource with the DataGridView, you should code (my code in vb but i guess you know what I mean)
CustomerBindingSource.EndEdit
ShugahDA.Update(shugahCustomerDS)

If you are not using BindingSource
ShugahDA.Update(shugahCustomerDS)

ShugahDA.Update() <-- I am not able to write it like that in my vs2008 unless ShugahDA is declared as oledbDataAdapter.

Below the form that you are working with, check if there is CustomerTableAdapter.

I am little lost of what you are using exactly, a oleDataAdapter created programatically or with Dataset Created at design time ?

Hi again. Sorry was missing in action for 4 days, went to travel. So back now i am.

Yes, my ShugahDA is oledbDataAdapter, and the dataset is generated at design time. And nope im not using binding source.

If you still remember that i said i've been following an example in the book, i've just found out something is wrong in the example too. The application too didn't make any changes to the database after updating the DataSet. I think i need to check my access or data provider

Make sure you call .BeginEdit() when you start to edit data and call .EndEdit() before you update the table adapter. Sometimes that will cause values to be lost.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.