Skip to content

Commit 01b05a4

Browse files
authored
Merge pull request #1596 from MicrosoftDocs/master
3/14 AM Publish
2 parents 89d8152 + aa6d0e6 commit 01b05a4

File tree

10 files changed

+342
-287
lines changed

10 files changed

+342
-287
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
##
4+
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5+
6+
# User-specific files
7+
*.suo
8+
*.user
9+
*.userosscache
10+
*.sln.docstates
11+
12+
# User-specific files (MonoDevelop/Xamarin Studio)
13+
*.userprefs
14+
15+
# Build results
16+
[Dd]ebug/
17+
[Dd]ebugPublic/
18+
[Rr]elease/
19+
[Rr]eleases/
20+
x64/
21+
x86/
22+
bld/
23+
[Bb]in/
24+
[Oo]bj/
25+
[Ll]og/
26+
27+
# Visual Studio 2015/2017 cache/options directory
28+
.vs/
29+
30+
# Visual Studio 2017 auto generated files
31+
Generated\ Files/
32+
33+
# .NET Core
34+
project.lock.json
35+
project.fragment.lock.json
36+
artifacts/
37+
**/Properties/launchSettings.json
38+
39+
# Files built by Visual Studio
40+
*_i.c
41+
*_p.c
42+
*_i.h
43+
*.ilk
44+
*.meta
45+
*.obj
46+
*.pch
47+
*.pdb
48+
*.pgc
49+
*.pgd
50+
*.rsp
51+
*.sbr
52+
*.tlb
53+
*.tli
54+
*.tlh
55+
*.tmp
56+
*.tmp_proj
57+
*.log
58+
*.vspscc
59+
*.vssscc
60+
.builds
61+
*.pidb
62+
*.svclog
63+
*.scc

docs/data-tools/codesnippet/CSharp/SimpleDataApp/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<configSections>
44
</configSections>
55
<connectionStrings>
6-
<add name="SimpleDataAppCS.Properties.Settings.connStr" connectionString="Data Source=(localdb)\ProjectsV13;Initial Catalog=Sales;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" />
6+
<add name="SimpleDataAppCS.Properties.Settings.connString" connectionString="Data Source=(localdb)\ProjectsV13;Initial Catalog=Sales;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" />
77
</connectionStrings>
88
<startup>
99
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />

docs/data-tools/codesnippet/CSharp/SimpleDataApp/FillOrCancel.cs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@ public FillOrCancel()
2222
/// </summary>
2323
private bool IsOrderIDValid()
2424
{
25-
// Check for input in the Order ID text box.
25+
// Check for input in the Order ID text box.
2626
if (txtOrderID.Text == "")
2727
{
2828
MessageBox.Show("Please specify the Order ID.");
2929
return false;
3030
}
3131

32-
// Check for characters other than integers.
32+
// Check for characters other than integers.
3333
else if (Regex.IsMatch(txtOrderID.Text, @"^\D*$"))
3434
{
35-
// Show message and clear input.
35+
// Show message and clear input.
3636
MessageBox.Show("Customer ID must contain only numbers.");
3737
txtOrderID.Clear();
3838
return false;
3939
}
4040
else
4141
{
42-
// Convert the text in the text box to an integer to send to the database.
42+
// Convert the text in the text box to an integer to send to the database.
4343
parsedOrderID = Int32.Parse(txtOrderID.Text);
4444
return true;
4545
}
@@ -48,43 +48,42 @@ private bool IsOrderIDValid()
4848

4949
//<Snippet2>
5050
/// <summary>
51-
/// Executes a t-SQL SELECT statement to obtain
52-
/// order data for a specified order ID, then
53-
/// displays it in the DataGridView on the form.
51+
/// Executes a t-SQL SELECT statement to obtain order data for a specified
52+
/// order ID, then displays it in the DataGridView on the form.
5453
/// </summary>
5554
private void btnFindByOrderID_Click(object sender, EventArgs e)
5655
{
5756
if (IsOrderIDValid())
5857
{
59-
using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.connStr))
58+
using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.connString))
6059
{
61-
// Define a t-SQL query string that has a parameter for orderID.
60+
// Define a t-SQL query string that has a parameter for orderID.
6261
const string sql = "SELECT * FROM Sales.Orders WHERE orderID = @orderID";
6362

64-
// Create a SqlCommand object.
63+
// Create a SqlCommand object.
6564
using (SqlCommand sqlCommand = new SqlCommand(sql, connection))
6665
{
67-
// Define the @orderID parameter and set its value.
66+
// Define the @orderID parameter and set its value.
6867
sqlCommand.Parameters.Add(new SqlParameter("@orderID", SqlDbType.Int));
6968
sqlCommand.Parameters["@orderID"].Value = parsedOrderID;
7069

7170
try
7271
{
7372
connection.Open();
7473

75-
// Run the query by calling ExecuteReader().
74+
// Run the query by calling ExecuteReader().
7675
using (SqlDataReader dataReader = sqlCommand.ExecuteReader())
7776
{
78-
// Create a data table to hold the retrieved data.
77+
// Create a data table to hold the retrieved data.
7978
DataTable dataTable = new DataTable();
8079

81-
// Load the data from SqlDataReader into the data table.
80+
// Load the data from SqlDataReader into the data table.
8281
dataTable.Load(dataReader);
8382

84-
// Display the data from the data table in the data grid view.
83+
// Display the data from the data table in the data grid view.
8584
this.dgvCustomerOrders.DataSource = dataTable;
8685

87-
// Close the SqlDataReader.
86+
// Close the SqlDataReader.
8887
dataReader.Close();
8988
}
9089
}
@@ -94,7 +93,7 @@ private void btnFindByOrderID_Click(object sender, EventArgs e)
9493
}
9594
finally
9695
{
97-
// Close the connection.
96+
// Close the connection.
9897
connection.Close();
9998
}
10099
}
@@ -110,10 +109,10 @@ private void btnCancelOrder_Click(object sender, EventArgs e)
110109
{
111110
if (IsOrderIDValid())
112111
{
113-
// Create the connection.
114-
using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.connStr))
112+
// Create the connection.
113+
using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.connString))
115114
{
116-
// Create the SqlCommand object and identify it as a stored procedure.
115+
// Create the SqlCommand object and identify it as a stored procedure.
117116
using (SqlCommand sqlCommand = new SqlCommand("Sales.uspCancelOrder", connection))
118117
{
119118
sqlCommand.CommandType = CommandType.StoredProcedure;
@@ -124,10 +123,10 @@ private void btnCancelOrder_Click(object sender, EventArgs e)
124123

125124
try
126125
{
127-
// Open the connection.
126+
// Open the connection.
128127
connection.Open();
129128

130-
// Run the command to execute the stored procedure.
129+
// Run the command to execute the stored procedure.
131130
sqlCommand.ExecuteNonQuery();
132131
}
133132
catch
@@ -136,7 +135,7 @@ private void btnCancelOrder_Click(object sender, EventArgs e)
136135
}
137136
finally
138137
{
139-
// Close connection.
138+
// Close connection.
140139
connection.Close();
141140
}
142141
}
@@ -152,19 +151,19 @@ private void btnFillOrder_Click(object sender, EventArgs e)
152151
{
153152
if (IsOrderIDValid())
154153
{
155-
// Create the connection.
156-
using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.connStr))
154+
// Create the connection.
155+
using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.connString))
157156
{
158-
// Create command and identify it as a stored procedure.
157+
// Create command and identify it as a stored procedure.
159158
using (SqlCommand sqlCommand = new SqlCommand("Sales.uspFillOrder", connection))
160159
{
161160
sqlCommand.CommandType = CommandType.StoredProcedure;
162161

163-
// Add the order ID input parameter for the stored procedure.
162+
// Add the order ID input parameter for the stored procedure.
164163
sqlCommand.Parameters.Add(new SqlParameter("@orderID", SqlDbType.Int));
165164
sqlCommand.Parameters["@orderID"].Value = parsedOrderID;
166165

167-
// Add the filled date input parameter for the stored procedure.
166+
// Add the filled date input parameter for the stored procedure.
168167
sqlCommand.Parameters.Add(new SqlParameter("@FilledDate", SqlDbType.DateTime, 8));
169168
sqlCommand.Parameters["@FilledDate"].Value = dtpFillDate.Value;
170169

@@ -181,7 +180,7 @@ private void btnFillOrder_Click(object sender, EventArgs e)
181180
}
182181
finally
183182
{
184-
// Close the connection.
183+
// Close the connection.
185184
connection.Close();
186185
}
187186
}

docs/data-tools/codesnippet/CSharp/SimpleDataApp/NewCustomer.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public NewCustomer()
1313
}
1414

1515
//<Snippet1>
16-
// Storage for IDENTITY values returned from database.
16+
// Storage for IDENTITY values returned from database.
1717
private int parsedCustomerID;
1818
private int orderID;
1919

@@ -38,21 +38,21 @@ private bool IsCustomerNameValid()
3838
/// </summary>
3939
private bool IsOrderDataValid()
4040
{
41-
// Verify that CustomerID is present.
41+
// Verify that CustomerID is present.
4242
if (txtCustomerID.Text == "")
4343
{
4444
MessageBox.Show("Please create customer account before placing order.");
4545
return false;
4646
}
47-
// Verify that Amount isn't 0.
47+
// Verify that Amount isn't 0.
4848
else if ((numOrderAmount.Value < 1))
4949
{
5050
MessageBox.Show("Please specify an order amount.");
5151
return false;
5252
}
5353
else
5454
{
55-
// Order can be submitted.
55+
// Order can be submitted.
5656
return true;
5757
}
5858
}
@@ -78,30 +78,30 @@ private void btnCreateAccount_Click(object sender, EventArgs e)
7878
{
7979
if (IsCustomerNameValid())
8080
{
81-
// Create the connection.
82-
using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.connStr))
81+
// Create the connection.
82+
using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.connString))
8383
{
84-
// Create a SqlCommand, and identify it as a stored procedure.
84+
// Create a SqlCommand, and identify it as a stored procedure.
8585
using (SqlCommand sqlCommand = new SqlCommand("Sales.uspNewCustomer", connection))
8686
{
8787
sqlCommand.CommandType = CommandType.StoredProcedure;
8888

89-
// Add input parameter for the stored procedure and specify what to use as its value.
89+
// Add input parameter for the stored procedure and specify what to use as its value.
9090
sqlCommand.Parameters.Add(new SqlParameter("@CustomerName", SqlDbType.NVarChar, 40));
9191
sqlCommand.Parameters["@CustomerName"].Value = txtCustomerName.Text;
9292

93-
// Add the output parameter.
93+
// Add the output parameter.
9494
sqlCommand.Parameters.Add(new SqlParameter("@CustomerID", SqlDbType.Int));
9595
sqlCommand.Parameters["@CustomerID"].Direction = ParameterDirection.Output;
9696

9797
try
9898
{
9999
connection.Open();
100100

101-
// Run the stored procedure.
101+
// Run the stored procedure.
102102
sqlCommand.ExecuteNonQuery();
103103

104-
// Customer ID is an IDENTITY value from the database.
104+
// Customer ID is an IDENTITY value from the database.
105105
this.parsedCustomerID = (int)sqlCommand.Parameters["@CustomerID"].Value;
106106

107107
// Put the Customer ID value into the read-only text box.
@@ -125,47 +125,47 @@ private void btnCreateAccount_Click(object sender, EventArgs e)
125125
/// </summary>
126126
private void btnPlaceOrder_Click(object sender, EventArgs e)
127127
{
128-
// Ensure the required input is present.
128+
// Ensure the required input is present.
129129
if (IsOrderDataValid())
130130
{
131-
// Create the connection.
132-
using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.connStr))
131+
// Create the connection.
132+
using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.connString))
133133
{
134-
// Create SqlCommand and identify it as a stored procedure.
134+
// Create SqlCommand and identify it as a stored procedure.
135135
using (SqlCommand sqlCommand = new SqlCommand("Sales.uspPlaceNewOrder", connection))
136136
{
137137
sqlCommand.CommandType = CommandType.StoredProcedure;
138138

139-
// Add the @CustomerID input parameter, which was obtained from uspNewCustomer.
139+
// Add the @CustomerID input parameter, which was obtained from uspNewCustomer.
140140
sqlCommand.Parameters.Add(new SqlParameter("@CustomerID", SqlDbType.Int));
141141
sqlCommand.Parameters["@CustomerID"].Value = this.parsedCustomerID;
142142

143-
// Add the @OrderDate input parameter.
143+
// Add the @OrderDate input parameter.
144144
sqlCommand.Parameters.Add(new SqlParameter("@OrderDate", SqlDbType.DateTime, 8));
145145
sqlCommand.Parameters["@OrderDate"].Value = dtpOrderDate.Value;
146146

147-
// Add the @Amount order amount input parameter.
147+
// Add the @Amount order amount input parameter.
148148
sqlCommand.Parameters.Add(new SqlParameter("@Amount", SqlDbType.Int));
149149
sqlCommand.Parameters["@Amount"].Value = numOrderAmount.Value;
150150

151151
// Add the @Status order status input parameter.
152-
// For a new order, the status is always O (open).
152+
// For a new order, the status is always O (open).
153153
sqlCommand.Parameters.Add(new SqlParameter("@Status", SqlDbType.Char, 1));
154154
sqlCommand.Parameters["@Status"].Value = "O";
155155

156-
// Add the return value for the stored procedure, which is the order ID.
156+
// Add the return value for the stored procedure, which is the order ID.
157157
sqlCommand.Parameters.Add(new SqlParameter("@RC", SqlDbType.Int));
158158
sqlCommand.Parameters["@RC"].Direction = ParameterDirection.ReturnValue;
159159

160160
try
161161
{
162-
//Open connection.
162+
//Open connection.
163163
connection.Open();
164164

165-
// Run the stored procedure.
165+
// Run the stored procedure.
166166
sqlCommand.ExecuteNonQuery();
167167

168-
// Display the order number.
168+
// Display the order number.
169169
this.orderID = (int)sqlCommand.Parameters["@RC"].Value;
170170
MessageBox.Show("Order number " + this.orderID + " has been submitted.");
171171
}

0 commit comments

Comments
 (0)