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