Update not working

N

Neil B

I'm developing a Web App in C#. The following method executes without
exceptions but the database does not get changed. The data is changed in the
record[0] at the point prior to executing the " adapter.Update(record);"
instruction.

Is there something else I should be doing to insure the update to take
effect???

Thanks, Neil


protected void UpdateUserFields(String id, String field, String value)
{

//***********************************************************// ***** Make
connection, process request, break connection
//***********************************************************
using (OdbcConnection connection =
new OdbcConnection(ConnectionBuilder().ConnectionString))
{
// ***** Make connection and get dataRows *****
String sql = "select * from Register where Id='" + id + "'";
OdbcDataAdapter adapter = new OdbcDataAdapter(sql,
connection);
DataSet dataSet = new DataSet();
try { connection.Open(); adapter.Fill(dataSet, "Register"); }
catch (Exception ex) { Console.WriteLine(ex.Message); }
DataRow[] record = dataSet.Tables["Register"].Select();
if (record.Count() == 0) return;

//****** Process update request ******
// Update the cpu id list in the user's registation record
if (field=="CpuId") record[0]["CpuId"]=value;


//****** Update the data base with changes ******
// Mark the changes for updating
record[0].AcceptChanges();

// Update the changes
adapter.Update(record);
}
}
 
N

Norman Yuan

Remove this line of code:

// Mark the changes for updating
record[0].AcceptChanges();

You need a bit study on when/why to use/not use
AcceptChanges()/RejectChanges().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top