-
Notifications
You must be signed in to change notification settings - Fork 330
Expand file tree
/
Copy pathSqlBatchCommand.xml
More file actions
143 lines (136 loc) · 6.14 KB
/
SqlBatchCommand.xml
File metadata and controls
143 lines (136 loc) · 6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<docs>
<members name="SqlBatchCommand">
<SqlBatchCommand>
<summary>
SqlBatchCommand allows for the execution of multiple SQL commands in a SqlBatch.
</summary>
</SqlBatchCommand>
<ctor1>
<summary>
Initializes a new <see cref="T:Microsoft.Data.SqlClient.SqlBatchCommand" />.
</summary>
<example>
The following example creates a <see cref="T:Microsoft.Data.SqlClient.SqlConnection" /> and a SqlBatch, then adds multiple <see cref="T:Microsoft.Data.SqlClient.SqlBatchCommand" /> objects to the batch. It then executes the batch, creating a <see cref="T:Microsoft.Data.SqlClient.SqlDataReader" /> . The example reads through the results of the batch commands, writing them to the console. Finally, the example closes the <see cref="T:Microsoft.Data.SqlClient.SqlDataReader" /> and then the <see cref="T:Microsoft.Data.SqlClient.SqlConnection" /> as the <c>using</c> blocks fall out of scope.
<code language="c#">
using Microsoft.Data.SqlClient;
class Program
{
static void Main()
{
string str = "Data Source=(local);Initial Catalog=Northwind;"
+ "Integrated Security=SSPI;Encrypt=False";
RunBatch(str);
}
static void RunBatch(string connString)
{
using var connection = new SqlConnection(connString);
connection.Open();
var batch = new SqlBatch(connection);
const int count = 10;
const string parameterName = "parameter";
for (int i = 0; i < count; i++)
{
var batchCommand = new SqlBatchCommand($"SELECT @{parameterName} as value");
batchCommand.Parameters.Add(new SqlParameter(parameterName, i));
batch.BatchCommands.Add(batchCommand);
}
// Optionally Prepare
batch.Prepare();
var results = new List<int>(count);
using (SqlDataReader reader = batch.ExecuteReader())
{
do
{
while (reader.Read())
{
results.Add(reader.GetFieldValue<int>(0));
}
} while (reader.NextResult());
}
Console.WriteLine(string.Join(", ", results));
}
}
</code>
</example>
</ctor1>
<ctor2>
<summary>
Initializes a new <see cref="T:Microsoft.Data.SqlClient.SqlBatchCommand" />.
</summary>
<param name="commandText">
The text of the <see cref="T:Microsoft.Data.SqlClient.SqlBatchCommand" />.
</param>
<param name="commandType">
Indicates how the <see cref="P:Microsoft.Data.SqlClient.SqlBatchCommand.CommandText" /> property is to be interpreted.
</param>
<param name="parameters">
A collection of <see cref="T:Microsoft.Data.SqlClient.SqlParameter" /> objects is used to create the <see cref="T:Microsoft.Data.SqlClient.SqlParameterCollection" />.
</param>
<param name="columnEncryptionSetting">
The encryption setting. For more information, see <see href="https://learn.microsoft.com/sql/relational-databases/security/encryption/always-encrypted-database-engine">Always Encrypted</see>.
</param>
</ctor2>
<Parameters>
<summary>
Gets the <see cref="T:Microsoft.Data.SqlClient.SqlParameterCollection" />.
</summary>
<value>
The parameters of the Transact-SQL statement or stored procedure. The default is an empty collection.
</value>
</Parameters>
<CommandBehavior>
<summary>
An instance of <see cref="T:System.Data.CommandBehavior" />, specifying options for statement execution and data retrieval.
Only <see cref="F:System.Data.CommandBehavior.SchemaOnly"/> and <see cref="F:System.Data.CommandBehavior.KeyInfo"/> are supported at the statement level.
</summary>
</CommandBehavior>
<ColumnEncryptionSetting>
<summary>
Not currently implemented.
The encryption setting. For more information, see <see href="https://learn.microsoft.com/sql/relational-databases/security/encryption/always-encrypted-database-engine">Always Encrypted</see>.
</summary>
</ColumnEncryptionSetting>
<CreateParameter>
<summary>
Creates a new instance of a <see cref="T:Microsoft.Data.SqlClient.SqlParameter" /> object.
</summary>
</CreateParameter>
<CanCreateParameter>
<summary>
Returns whether the <see cref="P:Microsoft.Data.SqlClient.SqlBatchCommand.CreateParameter" /> method is implemented.
</summary>
</CanCreateParameter>
<CommandText>
<summary>
Gets or sets the text command to run against the data source.
</summary>
<value>
The text command to execute. The default value is an empty string ("").
</value>
</CommandText>
<CommandType>
<summary>
Gets or sets how the <see cref="P:Microsoft.Data.SqlClient.SqlBatchCommand.CommandText" /> property is interpreted.
</summary>
<value>
One of the enumeration values that specifies how a command string is interpreted. The default is <see cref="F:System.Data.CommandType.Text" />.
</value>
</CommandType>
<DbParameterCollection>
<summary>
Gets the collection of <see cref="T:Microsoft.Data.SqlClient.SqlParameter" /> objects.
</summary>
<value>
The parameters of the SQL statement or stored procedure.
</value>
</DbParameterCollection>
<RecordsAffected>
<summary>
Gets the number of rows changed, inserted, or deleted by execution of this specific <see cref="T:Microsoft.Data.SqlClient.SqlBatchCommand" />.
</summary>
<value>
The number of rows changed, inserted, or deleted. -1 for SELECT statements; 0 if no rows were affected or the statement failed.
</value>
</RecordsAffected>
</members>
</docs>