Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / May 2008

Tip: Looking for answers? Try searching our database.

Update not working

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Neil B - 31 Mar 2008 19:06 GMT
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);
           }
       }
Norman Yuan - 31 Mar 2008 21:12 GMT
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().

> 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
[quoted text clipped - 41 lines]
>            }
>        }
Neil B - 10 May 2008 17:17 GMT
AcceptChanges() was the problem.

Thanks, Neil

> Remove this line of code:
>
[quoted text clipped - 49 lines]
> >            }
> >        }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.