Skip to content

Commit d6f2e29

Browse files
Docs | Add XML documentation for publishing library to .Net API Reference (#210)
Contributors: @JRahnama @v-kaywon @cheenamalhotra Changes with this PR: - Adds common XML doc snippets to be extracted for XML documentation - Adds Samples to repository included in documentation - Updated both NetFx and NetCore drivers with documentation includes. - GitIgnore update to exclude `nuget.exe` - build.proj now defaults to `BuildAllConfigurations` target. Addresses #197 - Added include tags in 'ref' classes for Visual Studio Intellisense support. Additional Changes in this PR: - `Microsoft.Data.SqlTypes.SqlFileStream` added in NetFx. - Existing tests run against the newly added SqlFileStream class. As of now, this PR brings documentation over from System.Data.SqlClient. Work to be continued to enhance missing docs in future PRs.
1 parent aa917d7 commit d6f2e29

File tree

423 files changed

+33307
-2046
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

423 files changed

+33307
-2046
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ bld/
3939
# Visual Studio 2017 auto generated files
4040
Generated\ Files/
4141

42+
# Visual Studio Code settings
43+
.vscode/
44+
4245
# MSTest test Results
4346
[Tt]est[Rr]esult*/
4447
[Bb]uild[Ll]og.*
@@ -351,3 +354,6 @@ MigrationBackup/
351354

352355
# Ionide (cross platform F# VS Code tools) working folder
353356
.ionide/
357+
358+
# Nuget package files
359+
.nuget/

build.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="15.0" DefaultTargets="BuildAll" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="15.0" DefaultTargets="BuildAllConfigurations" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="src/Directory.Build.props" />
44
<Import Project="$(ToolsDir)targets\GenerateNugetPackage.targets" />
55

doc/samples/DataColumn_DataType.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System;
2+
using System.Data;
3+
// <Snippet1>
4+
using Microsoft.Data.SqlClient;
5+
using System.Data.SqlTypes;
6+
7+
class Program
8+
{
9+
static void Main()
10+
{
11+
string connectionString = GetConnectionString();
12+
GetSqlTypesAW(connectionString);
13+
Console.ReadLine();
14+
}
15+
static private void GetSqlTypesAW(string connectionString)
16+
{
17+
// Create a DataTable and specify a SqlType
18+
// for each column.
19+
DataTable table = new DataTable();
20+
DataColumn icolumnolumn =
21+
table.Columns.Add("SalesOrderID", typeof(SqlInt32));
22+
DataColumn priceColumn =
23+
table.Columns.Add("UnitPrice", typeof(SqlMoney));
24+
DataColumn totalColumn =
25+
table.Columns.Add("LineTotal", typeof(SqlDecimal));
26+
DataColumn columnModifiedDate =
27+
table.Columns.Add("ModifiedDate", typeof(SqlDateTime));
28+
29+
// Open a connection to SQL Server and fill the DataTable
30+
// with data from the Sales.SalesOrderDetail table
31+
// in the AdventureWorks sample database.
32+
using (SqlConnection connection = new SqlConnection(connectionString))
33+
{
34+
string queryString =
35+
"SELECT TOP 5 SalesOrderID, UnitPrice, LineTotal, ModifiedDate "
36+
+ "FROM Sales.SalesOrderDetail WHERE LineTotal < @LineTotal";
37+
38+
// Create the SqlCommand.
39+
SqlCommand command = new SqlCommand(queryString, connection);
40+
41+
// Create the SqlParameter and assign a value.
42+
SqlParameter parameter =
43+
new SqlParameter("@LineTotal", SqlDbType.Decimal);
44+
parameter.Value = 1.5;
45+
command.Parameters.Add(parameter);
46+
47+
// Open the connection and load the data.
48+
connection.Open();
49+
SqlDataReader reader =
50+
command.ExecuteReader(CommandBehavior.CloseConnection);
51+
table.Load(reader);
52+
53+
// Close the SqlDataReader.
54+
reader.Close();
55+
}
56+
57+
// Display the SqlType of each column.
58+
Console.WriteLine("Data Types:");
59+
foreach (DataColumn column in table.Columns)
60+
{
61+
Console.WriteLine(" {0} -- {1}",
62+
column.ColumnName, column.DataType.UnderlyingSystemType);
63+
}
64+
65+
// Display the value for each row.
66+
Console.WriteLine("Values:");
67+
foreach (DataRow row in table.Rows)
68+
{
69+
Console.Write(" {0}, ", row["SalesOrderID"]);
70+
Console.Write(" {0}, ", row["UnitPrice"]);
71+
Console.Write(" {0}, ", row["LineTotal"]);
72+
Console.Write(" {0} ", row["ModifiedDate"]);
73+
Console.WriteLine();
74+
}
75+
}
76+
77+
static private string GetConnectionString()
78+
{
79+
// To avoid storing the connection string in your code,
80+
// you can retrieve it from a configuration file, using the
81+
// System.Configuration.ConfigurationSettings.AppSettings property
82+
return "Data Source=(local);Initial Catalog=AdventureWorks;"
83+
+ "Integrated Security=SSPI;";
84+
}
85+
}
86+
// </Snippet1>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// <Snippet1>
2+
using System;
3+
using System.Data;
4+
using Microsoft.Data.SqlClient;
5+
6+
class Program
7+
{
8+
// using Microsoft.Data.SqlClient;
9+
private static void TestGetValues(DataTableReader reader)
10+
{
11+
// Given a DataTableReader, use the GetValues
12+
// method to retrieve a full row of data.
13+
// Test the GetValues method, passing in an array large
14+
// enough for all the columns.
15+
Object[] values = new Object[reader.FieldCount];
16+
int fieldCount = reader.GetValues(values);
17+
18+
Console.WriteLine("reader.GetValues retrieved {0} columns.",
19+
fieldCount);
20+
for (int i = 0; i < fieldCount; i++)
21+
Console.WriteLine(values[i]);
22+
23+
Console.WriteLine();
24+
25+
// Now repeat, using an array that may contain a different
26+
// number of columns than the original data. This should work correctly,
27+
// whether the size of the array is larger or smaller than
28+
// the number of columns.
29+
30+
// Attempt to retrieve three columns of data.
31+
values = new Object[3];
32+
fieldCount = reader.GetValues(values);
33+
Console.WriteLine("reader.GetValues retrieved {0} columns.",
34+
fieldCount);
35+
for (int i = 0; i < fieldCount; i++)
36+
Console.WriteLine(values[i]);
37+
}
38+
// </Snippet1>
39+
40+
// <Snippet2>
41+
// using Microsoft.Data.SqlClient;
42+
private static void TestGetValues(SqlDataReader reader)
43+
{
44+
// Given a SqlDataReader, use the GetValues
45+
// method to retrieve a full row of data.
46+
// Test the GetValues method, passing in an array large
47+
// enough for all the columns.
48+
Object[] values = new Object[reader.FieldCount];
49+
int fieldCount = reader.GetValues(values);
50+
51+
Console.WriteLine("reader.GetValues retrieved {0} columns.",
52+
fieldCount);
53+
for (int i = 0; i < fieldCount; i++)
54+
Console.WriteLine(values[i]);
55+
56+
Console.WriteLine();
57+
58+
// Now repeat, using an array that may contain a different
59+
// number of columns than the original data. This should work correctly,
60+
// whether the size of the array is larger or smaller than
61+
// the number of columns.
62+
63+
// Attempt to retrieve three columns of data.
64+
values = new Object[3];
65+
fieldCount = reader.GetValues(values);
66+
Console.WriteLine("reader.GetValues retrieved {0} columns.",
67+
fieldCount);
68+
for (int i = 0; i < fieldCount; i++)
69+
Console.WriteLine(values[i]);
70+
}
71+
// </Snippet2>
72+
}

doc/samples/IBinarySerialize.cs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using System;
2+
using System.IO;
3+
using System.Data;
4+
using System.Data.SqlTypes;
5+
using Microsoft.Data.SqlClient.Server;
6+
using System.Text;
7+
8+
namespace test
9+
{
10+
11+
public class Class1 : IBinarySerialize
12+
{
13+
14+
[STAThread]
15+
static void Main(string[] args)
16+
{
17+
string fileName = "info.dat";
18+
Class1 temp = new Class1();
19+
20+
FileStream fs = new FileStream(fileName, FileMode.Create);
21+
BinaryWriter w = new BinaryWriter(fs);
22+
23+
temp.Write(w);
24+
25+
w.Close();
26+
fs.Close();
27+
28+
fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
29+
BinaryReader r = new BinaryReader(fs);
30+
31+
temp.Read(r);
32+
33+
Console.WriteLine("String value: " + temp.StringValue);
34+
Console.WriteLine("Double value: " + temp.DoubleValue);
35+
36+
r.Close();
37+
fs.Close();
38+
}
39+
40+
public string StringValue;
41+
public double DoubleValue;
42+
43+
//<Snippet1>
44+
// The binary layout is as follows:
45+
// Bytes 0 - 19: string text, padded to the right with null characters
46+
// Bytes 20+: Double value
47+
48+
// using Microsoft.Data.SqlClient.Server;
49+
public void Read(System.IO.BinaryReader r)
50+
{
51+
52+
int maxStringSize = 20;
53+
char[] chars;
54+
int stringEnd;
55+
string stringValue;
56+
double doubleValue;
57+
58+
// Read the characters from the binary stream.
59+
chars = r.ReadChars(maxStringSize);
60+
61+
// Find the start of the null character padding.
62+
stringEnd = Array.IndexOf(chars, '\0');
63+
64+
if (stringEnd == 0)
65+
{
66+
stringValue = null;
67+
return;
68+
}
69+
70+
// Build the string from the array of characters.
71+
stringValue = new String(chars, 0, stringEnd);
72+
73+
// Read the double value from the binary stream.
74+
doubleValue = r.ReadDouble();
75+
76+
// Set the object's properties equal to the values.
77+
this.StringValue = stringValue;
78+
this.DoubleValue = doubleValue;
79+
}
80+
//</Snippet1>
81+
82+
//<Snippet2>
83+
// The binary layout is as follows:
84+
// Bytes 0 - 19: string text, padded to the right with null characters
85+
// Bytes 20+: Double value
86+
87+
// using Microsoft.Data.SqlClient.Server;
88+
public void Write(System.IO.BinaryWriter w)
89+
{
90+
int maxStringSize = 20;
91+
string stringValue = "The value of PI: ";
92+
string paddedString;
93+
double value = 3.14159;
94+
95+
// Pad the string from the right with null characters.
96+
paddedString = stringValue.PadRight(maxStringSize, '\0');
97+
98+
// Write the string value one byte at a time.
99+
for (int i = 0; i < paddedString.Length; i++)
100+
{
101+
w.Write(paddedString[i]);
102+
}
103+
104+
// Write the double value.
105+
w.Write(value);
106+
}
107+
//</Snippet2>
108+
}
109+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// <Snippet1>
2+
using System;
3+
using System.Xml;
4+
using System.Data;
5+
using Microsoft.Data.SqlClient;
6+
using System.Data.Common;
7+
using System.Windows.Forms;
8+
9+
public class Form1 : Form
10+
{
11+
protected DataSet DataSet1;
12+
protected DataGrid dataGrid1;
13+
14+
15+
public void CreateSqlCommand()
16+
{
17+
SqlCommand command = new SqlCommand();
18+
command.CommandTimeout = 15;
19+
command.CommandType = CommandType.Text;
20+
}
21+
// </Snippet1>
22+
}

0 commit comments

Comments
 (0)