Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the operation of ADO.NET to update data

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces you what is the operation of ADO.NET updating data, the content is very detailed, interested friends can refer to, hope to be helpful to you.

When learning ADO.NET, you may encounter the problem of updating data with ADO.NET. Here we will introduce the solution to the problem of updating data with ADO.NET, and share it with you here. This is a task for getting started with EntityFramework. In this task, you save changes to the Course object that is bound to the DataGridView control to the database. You will also run the completed CourseManager application. Save changes to the object.

1. In the Toolbox, expand Common controls, drag the Button control to the CourseViewer forms designer, change the name of the control to saveChanges, and change the Text value to Update.

two。 In the CourseViewer forms designer, double-click the saveChanges control. The saveChanges_Click event handler method is created.

3. Paste the following code to save the object changes to the database.

DimnumChangesAsNewInteger Try 'Saveobjectchangestothedatabase,displayamessage,' andrefreshtheform. NumChanges=schoolContext.SaveChanges () MessageBox.Show (numChanges.ToString () + _ "change (s) savedtothedatabase.") Me.Refresh () CatchexAsException MessageBox.Show (ex.Message) EndTry

In the closeForm_Click event handler method, type the following code in closing the connection by releasing the long-running object context. This code releases the object context before closing the form.

'Disposetheobjectcontext. SchoolContext.Dispose ()

Build and run the class plan application from the Debug menu, click start debugging or start execution (do not debug). The application will be built and started. When the form is loaded, select a system from the ComboBox control. Courses belonging to the department are displayed. In DataGridView, update the course information or add a new course, and then click Update. The ADO.NET update data is saved to the database and a message box is displayed declaring the number of saved changes.

About ADO.NET update data operation is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report