Update Data By Using A TableAdapter - Visualstudio-docs - GitHub
Có thể bạn quan tâm
- Notifications You must be signed in to change notification settings
- Fork 1.7k
- Star 1.1k
- Code
- Pull requests 1
- Actions
- Projects
- Security 0
- Insights
Files
mainBreadcrumbs
- visualstudio-docs
- docs
- data-tools
Latest commit
History
History56 lines (40 loc) · 3.05 KB mainBreadcrumbs
- visualstudio-docs
- docs
- data-tools
File metadata and controls
- Preview
- Code
- Blame
| title | description | ms.date | ms.topic | dev_langs | helpviewer_keywords | author | ms.author | manager | ms.subservice | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Update data with TableAdapter (.NET Framework) | Update data in a dataset with .NET Framework application development in Visual Studio and return data to the database with the ADO.NET TableAdapter.Update method. | 11/04/2016 | how-to |
|
| ghogen | ghogen | mijacobs | data-tools |
[!INCLUDE Data access tech note]
After the data in your dataset has been modified and validated, you can send the updated data back to a database by calling the Update method of a TableAdapter. The Update method updates a single data table and runs the correct command (INSERT, UPDATE, or DELETE) based on the xref:System.Data.DataRow.RowState%2A of each data row in the table. When a dataset has related tables, Visual Studio generates a TableAdapterManager class that you use to do the updates. The TableAdapterManager class ensures that updates are made in the correct order based on the foreign-key constraints that are defined in the database. When you use data-bound controls, the databinding architecture creates a member variable of the TableAdapterManager class called tableAdapterManager.
Note
When you try to update a data source with the contents of a dataset, you can get errors. To avoid errors, we recommend that you put the code that calls the adapter's Update method inside a try/catch block.
The exact procedure for updating a data source can vary depending on business needs, but includes the following steps:
-
Call the adapter's Update method in a try/catch block.
-
If an exception is caught, locate the data row that caused the error.
-
Reconcile the problem in the data row (programmatically if you can, or by presenting the invalid row to the user for modification), and then try the update again (xref:System.Data.DataRow.HasErrors%2A, xref:System.Data.DataTable.GetErrors%2A).
Save data to a database
Call the Update method of a TableAdapter. Pass the name of the data table that contains the values to be written to the database.
To update a database by using a TableAdapter
-
Enclose the TableAdapter's Update method in a try/catch block. The following example shows how to update the contents of the Customers table in NorthwindDataSet from within a try/catch block.
C#
:::code language="csharp" source="../snippets/csharp/VS_Snippets_VBCSharp/VbRaddataSaving/CS/Form3.cs" id="Snippet9":::
VB
:::code language="vb" source="../snippets/visualbasic/VS_Snippets_VBCSharp/VbRaddataSaving/VB/Form3.vb" id="Snippet9":::
Related content
- Save data back to the database
Từ khóa » Visual Basic Tableadapter Update
-
Update Data By Using A TableAdapter - Visual Studio (Windows)
-
Update Data By Using A TableAdapter - Visual Studio - Microsoft Docs
-
When Updating A TableAdapter, The Insert/update/delete Instructions ...
-
Visual Basic TableAdapter - YouTube
-
VB.NET - Update Access Database Using Tableadapter Dbdirect ...
-
Update Tableadapter Database In Visual Studio - Stack Overflow
-
- Update Is Not A Member Of Tableadapter - Stack Overflow
-
Saving Dataset Changes With TableAdapter.Update(DataTable)
-
How To Update With Tableadapter
-
Update Alternatives: Using The TableAdapter Configuration Wizard
-
Vb Net Tableadapter Update Method In Access - Freshlasopa
-
Data Updating And Deleting With Visual Basic.NET - IEEE Xplore
-
Data Updating And Deleting With Visual Basic.NET - ResearchGate
-
Update Data Using A DataAdapter & TableAdapter