Skip to content

Commit 4c294c6

Browse files
Fix duplicated docs, and missing snippet ref (#4086)
1 parent 52c7149 commit 4c294c6

1 file changed

Lines changed: 2 additions & 99 deletions

File tree

doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml

Lines changed: 2 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,7 +2682,7 @@ If you use <xref:Microsoft.Data.SqlClient.SqlCommand.ExecuteReader%2A> or <xref:
26822682
## Examples
26832683
The following example creates a <xref:Microsoft.Data.SqlClient.SqlCommand>, and then executes it by passing a string that is a Transact-SQL SELECT statement, and a string to use to connect to the data source.
26842684
2685-
[!code-csharp[SqlCommand_ExecuteReader](~/../sqlclient/doc/samples/SqlCommand_ExecuteReader.cs)]
2685+
[!code-csharp[SqlCommand_ExecuteReader](~/../sqlclient/doc/samples/SqlCommand_ExecuteReader.cs#1)]
26862686
]]></format>
26872687
</remarks>
26882688
<exception cref="T:System.InvalidCastException">
@@ -2750,45 +2750,9 @@ If you use <xref:Microsoft.Data.SqlClient.SqlCommand.ExecuteReader%2A> or <xref:
27502750
## Examples
27512751
The following example creates a <xref:Microsoft.Data.SqlClient.SqlCommand>, and then executes it by passing a string that is a Transact-SQL SELECT statement, and a string to use to connect to the data source. <xref:System.Data.CommandBehavior> is set to <xref:System.Data.CommandBehavior.CloseConnection>.
27522752
2753-
[!code-csharp[SqlCommand_ExecuteReader2](~/../sqlclient/doc/samples/SqlCommand_ExecuteReader2.cs#1)]
2753+
[!code-csharp[SqlCommand_ExecuteReader2#1](~/../sqlclient/doc/samples/SqlCommand_ExecuteReader2.cs#1)]
27542754
]]></format>
27552755
</remarks>
2756-
<example>
2757-
<para>
2758-
The following example creates a <see cref="T:Microsoft.Data.SqlClient.SqlCommand" />, and then executes it by passing a string that is a Transact-SQL SELECT statement, and a string to use to connect to the data source. <see cref="T:System.Data.CommandBehavior" /> is set to <see cref="F:System.Data.CommandBehavior.CloseConnection" />.
2759-
</para>
2760-
<!-- SqlCommand_ExecuteReader2 -->
2761-
<code language="c#">
2762-
using System;
2763-
using System.Data;
2764-
using Microsoft.Data.SqlClient;
2765-
2766-
class Program
2767-
{
2768-
static void Main()
2769-
{
2770-
string str = "Data Source=(local);Initial Catalog=Northwind;"
2771-
+ "Integrated Security=SSPI";
2772-
string qs = "SELECT OrderID, CustomerID FROM dbo.Orders;";
2773-
CreateCommand(qs, str);
2774-
}
2775-
2776-
private static void CreateCommand(string queryString, string connectionString)
2777-
{
2778-
using (SqlConnection connection = new SqlConnection(connectionString))
2779-
{
2780-
SqlCommand command = new SqlCommand(queryString, connection);
2781-
connection.Open();
2782-
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
2783-
while (reader.Read())
2784-
{
2785-
Console.WriteLine(String.Format("{0}", reader[0]));
2786-
}
2787-
}
2788-
}
2789-
}
2790-
</code>
2791-
</example>
27922756
<exception cref="T:System.InvalidCastException">
27932757
<list type-="bullet">
27942758
<item><description>
@@ -3526,67 +3490,6 @@ The following example demonstrates how to create a <xref:Microsoft.Data.SqlClien
35263490
[!code-csharp[SqlParameterCollection.AddWithValue#1](~/../sqlclient/doc/samples/SqlParameterCollection_AddWithValue.cs#1)]
35273491
]]></format>
35283492
</remarks>
3529-
<example>
3530-
<para>
3531-
The following example demonstrates how to create a <see cref="T:Microsoft.Data.SqlClient.SqlCommand" /> and add parameters to the <see cref="T:Microsoft.Data.SqlClient.SqlParameterCollection" />.
3532-
</para>
3533-
<!-- SqlParameterCollection_AddWithValue -->
3534-
<code language="c#">
3535-
using System;
3536-
using System.Data;
3537-
using Microsoft.Data.SqlClient;
3538-
3539-
class Program
3540-
{
3541-
static void Main()
3542-
{
3543-
string connectionString = GetConnectionString();
3544-
string demo = @"&lt;StoreSurvey xmlns=""http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/StoreSurvey""&gt;&lt;AnnualSales&gt;1500000&lt;/AnnualSales&gt;&lt;AnnualRevenue&gt;150000&lt;/AnnualRevenue&gt;&lt;BankName&gt;Primary International&lt;/BankName&gt;&lt;BusinessType&gt;OS&lt;/BusinessType&gt;&lt;YearOpened&gt;1974&lt;/YearOpened&gt;&lt;Specialty&gt;Road&lt;/Specialty&gt;&lt;SquareFeet&lt;38000&lt;/SquareFeet&gt;&lt;Brands&gt;3&lt;/Brands&gt;&lt;Internet&gt;DSL&lt;/Internet&gt;&lt;NumberEmployees&gt;40&lt;/NumberEmployees&gt;&lt;/StoreSurvey&gt;";
3545-
Int32 id = 3;
3546-
UpdateDemographics(id, demo, connectionString);
3547-
Console.ReadLine();
3548-
}
3549-
private static void UpdateDemographics(Int32 customerID,
3550-
string demoXml, string connectionString)
3551-
{
3552-
// Update the demographics for a store, which is stored
3553-
// in an xml column.
3554-
string commandText = "UPDATE Sales.Store SET Demographics = @demographics "
3555-
+ "WHERE CustomerID = @ID;";
3556-
3557-
using (SqlConnection connection = new SqlConnection(connectionString))
3558-
{
3559-
SqlCommand command = new SqlCommand(commandText, connection);
3560-
command.Parameters.Add("@ID", SqlDbType.Int);
3561-
command.Parameters["@ID"].Value = customerID;
3562-
3563-
// Use AddWithValue to assign Demographics.
3564-
// SQL Server will implicitly convert strings into XML.
3565-
command.Parameters.AddWithValue("@demographics", demoXml);
3566-
3567-
try
3568-
{
3569-
connection.Open();
3570-
Int32 rowsAffected = command.ExecuteNonQuery();
3571-
Console.WriteLine("RowsAffected: {0}", rowsAffected);
3572-
}
3573-
catch (Exception ex)
3574-
{
3575-
Console.WriteLine(ex.Message);
3576-
}
3577-
}
3578-
}
3579-
3580-
static private string GetConnectionString()
3581-
{
3582-
// To avoid storing the connection string in your code,
3583-
// you can retrieve it from a configuration file.
3584-
return "Data Source=(local);Initial Catalog=AdventureWorks;"
3585-
+ "Integrated Security=SSPI";
3586-
}
3587-
}
3588-
</code>
3589-
</example>
35903493
</Parameters>
35913494
<Prepare>
35923495
<summary>

0 commit comments

Comments
 (0)