Skip to content

Commit fde363a

Browse files
committed
Merged main into live
2 parents 7246b31 + 48955d6 commit fde363a

File tree

5 files changed

+54
-88
lines changed

5 files changed

+54
-88
lines changed

.openpublishing.redirection.mac.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
"redirect_url": "/visualstudio/gamedev/unity/get-started/getting-started-with-visual-studio-tools-for-unity",
5656
"redirect_document_id": false
5757
},
58+
{
59+
"source_path_from_root": "/mac/what-happened-to-vs-for-mac.md",
60+
"redirect_url": "/visualstudio/releases/2022/what-happened-to-vs-for-mac",
61+
"redirect_document_id": false
62+
},
5863
{
5964
"source_path": "mac/2017/accessibility-keyboard.md",
6065
"redirect_url": "/previous-versions/visualstudio/mac/accessibility-keyboard",
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: Data technology note
33
author: ghogen
4-
description: Note saying that ADO data technologies are not recommended for new development.
4+
description: Note saying that ADO data technologies aren't recommended for new development.
55
ms.author: ghogen
6-
ms.date: 04/26/2023
6+
ms.date: 08/26/2024
77
ms.subservice: data-tools
88
ms.topic: include
99
---
1010
> [!NOTE]
11-
> Datasets and related classes are legacy .NET Framework technologies from the early 2000s that enable applications to work with data in memory while the applications are disconnected from the database. They are especially useful for applications that enable users to modify data and persist the changes back to the database. Although datasets have proven to be a very successful technology, we recommend that new .NET applications use [Entity Framework Core](/ef/). Entity Framework provides a more natural way to work with tabular data as object models, and it has a simpler programming interface.
11+
> Datasets and related classes are legacy .NET Framework technologies from the early 2000s that enable applications to work with data in memory while the applications are disconnected from the database. The technologies are especially useful for applications that enable users to modify data and persist the changes back to the database. Although datasets have proven to be a very successful technology, we recommend that new .NET applications use [Entity Framework Core](/ef/). Entity Framework provides a more natural way to work with tabular data as object models, and it has a simpler programming interface.
Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: Insert records into a database (.NET Framework)
3-
description: Insert new records into a database with .NET Framework application development in Visual Studio, including the ADO.NET TableAdapter.Update method.
4-
ms.date: 07/10/2024
2+
title: Insert records into database (.NET Framework)
3+
description: Insert new records into a database with .NET Framework application development in Visual Studio, including the ADO.NET TableAdapter Update method.
4+
ms.date: 08/26/2024
55
ms.topic: how-to
66
dev_langs:
77
- VB
@@ -16,56 +16,74 @@ author: ghogen
1616
ms.author: ghogen
1717
manager: mijacobs
1818
ms.subservice: data-tools
19+
20+
#customer intent: As a developer, I want to develop .NET Framework applications in Visual Studio, so I can insert new records into a database with TableAdapters or command objects.
1921
---
2022

2123
# Insert new records into a database in .NET Framework applications
2224

25+
To insert new records into a database with [ADO.NET](/dotnet/framework/data/adonet/) in a .NET Framework project, the common approach is to use [TableAdapter](../data-tools/create-and-configure-tableadapters.md) methods. TableAdapters enable communication between your application and database. They provide different ways to insert new records into a database, depending on the requirements of your application. You can use the `TableAdapter.Update` method or one of the TableAdapter [DBDirect](save-data-with-the-tableadapter-dbdirect-methods.md) methods (specifically, the `TableAdapter.Insert` method).
26+
27+
This article describes how to insert records into a database for an application built with ADO.NET and the .NET Framework by using Visual Basic (VB) or C#. If your application configuration uses Entity Framework 6, see [Adding a new entity to the context](/ef/ef6/saving/change-tracking/entity-state#adding-a-new-entity-to-the-context), or for Entity Framework Core, see [Adding data](/ef/core/saving/basic#adding-data).
28+
2329
[!INCLUDE [Data access tech note](./includes/data-technology-note.md)]
2430

25-
To insert new records into a database with [ADO.NET](/dotnet/framework/data/adonet/) in a .NET Framework project, you can use the `TableAdapter.Update` method, or one of the TableAdapter's DBDirect methods (specifically the `TableAdapter.Insert` method). For more information, see [TableAdapter](../data-tools/create-and-configure-tableadapters.md).
31+
## Prerequisites
2632

27-
If your application doesn't use TableAdapters, you can use command objects (for example, <xref:System.Data.SqlClient.SqlCommand>) to insert new records in your database.
33+
- To work with TableAdapter methods, you need to have an available instance. For more information, see [Create and configure TableAdapters in .NET Framework applications](create-and-configure-tableadapters.md).
2834

29-
If your application uses datasets to store data, use the `TableAdapter.Update` method. The `Update` method sends all changes (updates, inserts, and deletes) to the database.
35+
- **.NET security**: You must have access to the database you're trying to connect to, and permission to perform inserts into the desired table.
3036

31-
If your application uses objects to store data, or if you want finer control over creating new records in the database, use the `TableAdapter.Insert` method.
37+
## Choose insertion method
3238

33-
If your TableAdapter doesn't have an `Insert` method, it means that either the TableAdapter is configured to use stored procedures, or its `GenerateDBDirectMethods` property is set to `false`. Try setting the TableAdapter's `GenerateDBDirectMethods` property to `true` from within the **Dataset Designer**, and then save the dataset. This action regenerates the TableAdapter. If the TableAdapter still doesn't have an `Insert` method, the table probably doesn't provide enough schema information to distinguish between individual rows (for example, there might be no primary key set on the table).
39+
There are different approaches for inserting records into a database based on your application scenario. The following table summarizes the options:
3440

35-
> [!NOTE]
36-
> This article applies to ADO.NET and .NET Framework development. For the same task with Entity Framework 6, see [Adding a new entity to the context](/ef/ef6/saving/change-tracking/entity-state#adding-a-new-entity-to-the-context). For Entity Framework Core, see [Adding data](/ef/core/saving/basic#adding-data).
41+
| Scenario | Approach | Notes |
42+
| --- | --- | --- |
43+
| App uses *datasets* to store data | Use the [TableAdapter.Update](#insert-new-records-with-tableadapterupdate-method) method to send all changes to the database | Changes include updates, insertions, and deletions. |
44+
| App uses *objects* to store data | Use the [TableAdapter.Insert](#insert-new-records-with-tableadapterinsert-method) method to insert new records into the database | This approach enables you to have finer control over creating new records. |
45+
| App uses TableAdapters, `Insert` method not available | Set the TableAdapter `GenerateDBDirectMethods` property to `true` from within the **Dataset Designer** and save the dataset to regenerate the TableAdapter | If your TableAdapter doesn't have an `Insert` method, the TableAdapter is either configured to use stored procedures or the `GenerateDBDirectMethods` property is set to `false`. <br> If the `Insert` method remains unavailable after regenerating the TableAdapter, the table probably doesn't provide enough schema information to distinguish between individual rows (for example, there might be no primary key set on the table). |
46+
| App doesn't use TableAdapters | Use [command objects](#insert-new-records-with-command-objects) to insert new records into the database | Example: <xref:System.Data.SqlClient.SqlCommand> |
3747

3848
## Insert new records by using TableAdapters
3949

40-
TableAdapters provide different ways to insert new records into a database, depending on the requirements of your application.
50+
If your application uses datasets to store data, you can add new records to the desired <xref:System.Data.DataTable> in the dataset, and then call the `TableAdapter.Update` method. The `TableAdapter.Update` method sends any changes in the <xref:System.Data.DataTable> to the database, including modified and deleted records.
4151

42-
If your application uses datasets to store data, you can add new records to the desired <xref:System.Data.DataTable> in the dataset, and then call the `TableAdapter.Update` method. The `TableAdapter.Update` method sends any changes in the <xref:System.Data.DataTable> to the database (including modified and deleted records).
52+
### Insert new records with TableAdapter.Update method
4353

44-
### To insert new records into a database by using the TableAdapter.Update method
54+
The following procedure demonstrates how to insert new records into a database by using the `TableAdapter.Update` method:
4555

4656
1. Add new records to the desired <xref:System.Data.DataTable> by creating a new <xref:System.Data.DataRow> and adding it to the <xref:System.Data.DataTable.Rows%2A> collection.
4757

48-
2. After the new rows are added to the <xref:System.Data.DataTable>, call the `TableAdapter.Update` method. You can control the amount of data to update by passing in either an entire <xref:System.Data.DataSet>, a <xref:System.Data.DataTable>, an array of <xref:System.Data.DataRow>s, or a single <xref:System.Data.DataRow>.
58+
1. After you add the new rows to the <xref:System.Data.DataTable>, call the `TableAdapter.Update` method. You can control the amount of data to update by passing one of the following parameter values:
4959

50-
The following code shows how to add a new record to a <xref:System.Data.DataTable> and then call the `TableAdapter.Update` method to save the new row to the database. (This example uses the `Region` table in the Northwind database.)
60+
- An entire <xref:System.Data.DataSet>
61+
- A <xref:System.Data.DataTable>
62+
- An array of <xref:System.Data.DataRow>s
63+
- A single <xref:System.Data.DataRow>
64+
65+
The following code shows how to add a new record to a <xref:System.Data.DataTable> and then call the `TableAdapter.Update` method to save the new row to the database. This example uses the `Region` table in the Northwind database.
5166

5267
### [C#](#tab/csharp)
68+
5369
:::code language="csharp" source="../snippets/csharp/VS_Snippets_VBCSharp/VbRaddataSaving/CS/Form5.cs" id="Snippet14":::
5470

5571
### [VB](#tab/vb)
72+
5673
:::code language="vb" source="../snippets/visualbasic/VS_Snippets_VBCSharp/VbRaddataSaving/VB/Form5.vb" id="Snippet14":::
74+
5775
---
5876

59-
### To insert new records into a database by using the TableAdapter.Insert method
77+
### Insert new records with TableAdapter.Insert method
6078

61-
If your application uses objects to store data, you can use the `TableAdapter.Insert` method to create new rows directly in the database. The `Insert` method accepts the individual values for each column as parameters. Calling the method inserts a new record into the database with the parameter values passed in.
79+
If your application uses objects to store data, you can use the `TableAdapter.Insert` method to create new rows directly in the database. The `Insert` method accepts the individual values for each column as parameters. When you call the method, a new record is inserted into the database with the passed parameter values.
6280

63-
- Call the TableAdapter's `Insert` method, passing in the values for each column as parameters.
81+
- Call the TableAdapter's `Insert` method, and pass the values for each column as parameters.
6482

65-
The following procedure demonstrates using the `TableAdapter.Insert` method to insert rows. This example inserts data into the `Region` table in the Northwind database.
83+
The following procedure demonstrates how to use the `TableAdapter.Insert` method to insert rows. This example inserts data into the `Region` table in the Northwind database.
6684

6785
> [!NOTE]
68-
> If you do not have an instance available, instantiate the TableAdapter you want to use.
86+
> If you don't have an instance available, instantiate the TableAdapter that you want to use.
6987
7088
### [C#](#tab/csharp)
7189

@@ -74,17 +92,16 @@ The following procedure demonstrates using the `TableAdapter.Insert` method to i
7492
### [VB](#tab/vb)
7593

7694
:::code language="vb" source="../snippets/visualbasic/VS_Snippets_VBCSharp/VbRaddataSaving/VB/Class1.vb" id="Snippet15":::
77-
---
7895

79-
## Insert new records by using command objects
96+
---
8097

81-
You can insert new records directly into a database using command objects.
98+
## Insert new records with command objects
8299

83-
### To insert new records into a database by using command objects
100+
You can insert new records directly into a database by using command objects.
84101

85102
- Create a new command object, and then set its `Connection`, `CommandType`, and `CommandText` properties.
86103

87-
The following example demonstrates inserting records into a database using command object. It inserts data into the `Region` table in the Northwind database.
104+
The following procedure demonstrates how to insert records into a database by using command object. This example insert data into the `Region` table in the Northwind database.
88105

89106
### [C#](#tab/csharp)
90107

@@ -93,12 +110,10 @@ The following example demonstrates inserting records into a database using comma
93110
### [VB](#tab/vb)
94111

95112
:::code language="vb" source="../snippets/visualbasic/VS_Snippets_VBCSharp/VbRaddataSaving/VB/Class1.vb" id="Snippet16":::
96-
---
97-
98-
## .NET security
99113

100-
You must have access to the database you're trying to connect to, and permission to perform inserts into the desired table.
114+
---
101115

102116
## Related content
103117

104-
- [Save data back to the database](../data-tools/save-data-back-to-the-database.md)
118+
- [Save data back to the database](save-data-back-to-the-database.md)
119+
- [Save data with the TableAdapter DBDirect methods in .NET Framework applications](save-data-with-the-tableadapter-dbdirect-methods.md)

mac/TOC.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- name: IDE tour
77
href: ide-tour.md
88
- name: "What's happening to Visual Studio for Mac"
9-
href: what-happened-to-vs-for-mac.md
9+
href: /visualstudio/releases/2022/what-happened-to-vs-for-mac
1010
- name: Installation
1111
items:
1212
- name: Install

0 commit comments

Comments
 (0)