Update not working


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);"

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

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,
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

// Update the changes

Norman Yuan

Remove this line of code:

// Mark the changes for updating

You need a bit study on when/why to use/not use

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