Skip to content

Commit 476d526

Browse files
committed
add project files
1 parent 7794853 commit 476d526

File tree

13 files changed

+135
-200
lines changed

13 files changed

+135
-200
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="System.Data.Odbc" />
10+
</ItemGroup>
11+
12+
</Project>
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
using System;
2-
using System.Xml;
3-
using System.Data;
42
using System.Data.Odbc;
5-
using System.Data.Common;
6-
using System.Windows.Forms;
73

8-
public class Form1: Form
4+
public class Example
95
{
10-
protected DataSet DataSet1;
11-
protected DataGrid dataGrid1;
6+
// <Snippet1>
7+
public void CreateOdbcConnection()
8+
{
9+
string connectionString = "...";
1210

13-
// <Snippet1>
14-
public void CreateOdbcConnection()
15-
{
16-
string connectionString = "...";
11+
using (OdbcConnection connection = new(connectionString))
12+
{
13+
connection.Open();
14+
Console.WriteLine($"ServerVersion: {connection.ServerVersion}"
15+
+ $"\nDatabase: {connection.Database}");
1716

18-
using (OdbcConnection connection = new OdbcConnection(connectionString))
19-
{
20-
connection.Open();
21-
Console.WriteLine("ServerVersion: " + connection.ServerVersion
22-
+ "\nDatabase: " + connection.Database);
23-
24-
// The connection is automatically closed at
25-
// the end of the Using block.
26-
}
27-
}
28-
// </Snippet1>
17+
// The connection is automatically closed at
18+
// the end of the Using block.
19+
}
20+
}
21+
// </Snippet1>
2922
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="System.Data.Odbc" />
10+
</ItemGroup>
11+
12+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0-windows</TargetFramework>
6+
<UseWindowsForms>true</UseWindowsForms>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.1" />
11+
</ItemGroup>
12+
13+
</Project>

snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlDataAdapter.RowUpdated Example/CS/source.cs

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
using System;
2-
using System.Xml;
32
using System.Data;
4-
using System.Data.SqlClient;
5-
using System.Data.Common;
63
using System.Windows.Forms;
4+
using Microsoft.Data.SqlClient;
75

8-
public class Form1: Form
6+
public class Form1 : Form
97
{
10-
private DataSet DataSet1;
11-
private DataGrid dataGrid1;
12-
138
// <Snippet1>
149
// handler for RowUpdating event
1510
private static void OnRowUpdating(object sender, SqlRowUpdatingEventArgs e)
@@ -29,35 +24,35 @@ public static int Main()
2924
const string queryString = "SELECT * FROM Products";
3025

3126
// create DataAdapter
32-
SqlDataAdapter adapter = new SqlDataAdapter(queryString, connectionString);
33-
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
27+
SqlDataAdapter adapter = new(queryString, connectionString);
28+
SqlCommandBuilder builder = new(adapter);
3429

3530
// Create and fill DataSet (select only first 5 rows)
36-
DataSet dataSet = new DataSet();
31+
DataSet dataSet = new();
3732
adapter.Fill(dataSet, 0, 5, "Table");
3833

3934
// Modify DataSet
4035
DataTable table = dataSet.Tables["Table"];
4136
table.Rows[0][1] = "new product";
4237

4338
// add handlers
44-
adapter.RowUpdating += new SqlRowUpdatingEventHandler( OnRowUpdating );
45-
adapter.RowUpdated += new SqlRowUpdatedEventHandler( OnRowUpdated );
39+
adapter.RowUpdating += new SqlRowUpdatingEventHandler(OnRowUpdating);
40+
adapter.RowUpdated += new SqlRowUpdatedEventHandler(OnRowUpdated);
4641

4742
// update, this operation fires two events
4843
// (RowUpdating/RowUpdated) per changed row
4944
adapter.Update(dataSet, "Table");
5045

5146
// remove handlers
52-
adapter.RowUpdating -= new SqlRowUpdatingEventHandler( OnRowUpdating );
53-
adapter.RowUpdated -= new SqlRowUpdatedEventHandler( OnRowUpdated );
47+
adapter.RowUpdating -= new SqlRowUpdatingEventHandler(OnRowUpdating);
48+
adapter.RowUpdated -= new SqlRowUpdatedEventHandler(OnRowUpdated);
5449
return 0;
5550
}
5651

5752
private static void PrintEventArgs(SqlRowUpdatingEventArgs args)
5853
{
5954
Console.WriteLine("OnRowUpdating");
60-
Console.WriteLine(" event args: ("+
55+
Console.WriteLine(" event args: (" +
6156
" command=" + args.Command +
6257
" commandType=" + args.StatementType +
6358
" status=" + args.Status + ")");
@@ -66,7 +61,7 @@ private static void PrintEventArgs(SqlRowUpdatingEventArgs args)
6661
private static void PrintEventArgs(SqlRowUpdatedEventArgs args)
6762
{
6863
Console.WriteLine("OnRowUpdated");
69-
Console.WriteLine( " event args: ("+
64+
Console.WriteLine(" event args: (" +
7065
" command=" + args.Command +
7166
" commandType=" + args.StatementType +
7267
" recordsAffected=" + args.RecordsAffected +
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,13 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
33
<PropertyGroup>
4-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6-
<ProductVersion>9.0.20612</ProductVersion>
7-
<SchemaVersion>2.0</SchemaVersion>
8-
<ProjectGuid>{F2593E93-91A2-4F64-88A4-7E3861B3FE01}</ProjectGuid>
9-
<OutputType>WinExe</OutputType>
10-
<AppDesignerFolder>Properties</AppDesignerFolder>
11-
<RootNamespace>DataViewSamples</RootNamespace>
12-
<AssemblyName>DataViewSamples</AssemblyName>
13-
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
14-
<FileAlignment>512</FileAlignment>
15-
<Nonshipping>true</Nonshipping>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0-windows</TargetFramework>
6+
<UseWindowsForms>true</UseWindowsForms>
167
</PropertyGroup>
17-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18-
<DebugSymbols>true</DebugSymbols>
19-
<DebugType>full</DebugType>
20-
<Optimize>false</Optimize>
21-
<OutputPath>bin\Debug\</OutputPath>
22-
<DefineConstants>DEBUG;TRACE</DefineConstants>
23-
<ErrorReport>prompt</ErrorReport>
24-
<WarningLevel>4</WarningLevel>
25-
</PropertyGroup>
26-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27-
<DebugType>pdbonly</DebugType>
28-
<Optimize>true</Optimize>
29-
<OutputPath>bin\Release\</OutputPath>
30-
<DefineConstants>TRACE</DefineConstants>
31-
<ErrorReport>prompt</ErrorReport>
32-
<WarningLevel>4</WarningLevel>
33-
</PropertyGroup>
34-
<ItemGroup>
35-
<Reference Include="System" />
36-
<Reference Include="System.Core">
37-
<RequiredTargetFramework>3.5</RequiredTargetFramework>
38-
</Reference>
39-
<Reference Include="System.Xml.Linq">
40-
<RequiredTargetFramework>3.5</RequiredTargetFramework>
41-
</Reference>
42-
<Reference Include="System.Data.DataSetExtensions">
43-
<RequiredTargetFramework>3.5</RequiredTargetFramework>
44-
</Reference>
45-
<Reference Include="System.Data" />
46-
<Reference Include="System.Deployment" />
47-
<Reference Include="System.Drawing" />
48-
<Reference Include="System.Windows.Forms" />
49-
<Reference Include="System.Xml" />
50-
</ItemGroup>
8+
519
<ItemGroup>
52-
<Compile Include="Form1.cs">
53-
<SubType>Form</SubType>
54-
</Compile>
55-
<Compile Include="Form1.Designer.cs">
56-
<DependentUpon>Form1.cs</DependentUpon>
57-
</Compile>
58-
<Compile Include="Program.cs" />
59-
<Compile Include="Properties\AssemblyInfo.cs" />
60-
<EmbeddedResource Include="Form1.resx">
61-
<SubType>Designer</SubType>
62-
<DependentUpon>Form1.cs</DependentUpon>
63-
</EmbeddedResource>
64-
<EmbeddedResource Include="Properties\Resources.resx">
65-
<Generator>ResXFileCodeGenerator</Generator>
66-
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
67-
<SubType>Designer</SubType>
68-
</EmbeddedResource>
69-
<Compile Include="Properties\Resources.Designer.cs">
70-
<AutoGen>True</AutoGen>
71-
<DependentUpon>Resources.resx</DependentUpon>
72-
</Compile>
73-
<None Include="Properties\Settings.settings">
74-
<Generator>SettingsSingleFileGenerator</Generator>
75-
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
76-
</None>
77-
<Compile Include="Properties\Settings.Designer.cs">
78-
<AutoGen>True</AutoGen>
79-
<DependentUpon>Settings.settings</DependentUpon>
80-
<DesignTimeSharedInput>True</DesignTimeSharedInput>
81-
</Compile>
10+
<PackageReference Include="Microsoft.Data.SqlClient" />
8211
</ItemGroup>
83-
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
84-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
85-
Other similar extension points exist, see Microsoft.Common.targets.
86-
<Target Name="BeforeBuild">
87-
</Target>
88-
<Target Name="AfterBuild">
89-
</Target>
90-
-->
91-
</Project>
12+
13+
</Project>

snippets/csharp/VS_Snippets_ADO.NET/DP DataView Samples/CS/Form1.cs

+20-18
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.ComponentModel;
43
using System.Data;
5-
using System.Data.SqlClient;
6-
using System.Data.Common;
7-
using System.Drawing;
4+
using System.Globalization;
85
using System.Linq;
96
using System.Text;
107
using System.Windows.Forms;
11-
using System.Globalization;
8+
using Microsoft.Data.SqlClient;
129

1310
namespace DataViewSamples
1411
{
@@ -84,14 +81,14 @@ private void FillDataSet(DataSet ds)
8481
// Add data relations.
8582
DataTable orderHeader = ds.Tables["SalesOrderHeader"];
8683
DataTable orderDetail = ds.Tables["SalesOrderDetail"];
87-
DataRelation order = new DataRelation("SalesOrderHeaderDetail",
84+
DataRelation order = new("SalesOrderHeaderDetail",
8885
orderHeader.Columns["SalesOrderID"],
8986
orderDetail.Columns["SalesOrderID"], true);
9087
ds.Relations.Add(order);
9188

9289
DataTable contact = ds.Tables["Contact"];
9390
DataTable orderHeader2 = ds.Tables["SalesOrderHeader"];
94-
DataRelation orderContact = new DataRelation("SalesOrderContact",
91+
DataRelation orderContact = new("SalesOrderContact",
9592
contact.Columns["ContactID"],
9693
orderHeader2.Columns["ContactID"], true);
9794
ds.Relations.Add(orderContact);
@@ -113,14 +110,16 @@ static private string SoundEx(string word)
113110
if (size > 1)
114111
{
115112
// Convert the word to uppercase characters.
116-
word = word.ToUpper(System.Globalization.CultureInfo.InvariantCulture);
113+
word = word.ToUpper(CultureInfo.InvariantCulture);
117114

118115
// Convert the word to a character array.
119116
char[] chars = word.ToCharArray();
120117

121118
// Buffer to hold the character codes.
122-
StringBuilder buffer = new StringBuilder();
123-
buffer.Length = 0;
119+
StringBuilder buffer = new()
120+
{
121+
Length = 0
122+
};
124123

125124
// The current and previous character codes.
126125
int prevCode = 0;
@@ -227,8 +226,8 @@ private void button2_Click(object sender, EventArgs e)
227226

228227
EnumerableRowCollection<DataRow> query =
229228
from order in orders.AsEnumerable()
230-
where (order.Field<Int16>("OrderQty") > 2 &&
231-
order.Field<Int16>("OrderQty") < 6)
229+
where (order.Field<short>("OrderQty") > 2 &&
230+
order.Field<short>("OrderQty") < 6)
232231
select order;
233232

234233
DataView view = query.AsDataView();
@@ -471,7 +470,7 @@ where contact.Field<string>("LastName") == "Hernandez"
471470
bindingSource1.DataSource = view;
472471
dataGridView1.AutoResizeColumns();
473472

474-
// </SnippetLDVFromQueryWhere2>
473+
// </SnippetLDVFromQueryWhere2>
475474
}
476475

477476
private void button18_Click(object sender, EventArgs e)
@@ -552,7 +551,7 @@ orderby product.Field<Decimal>("ListPrice"), product.Field<string>("Color")
552551

553552
view.Sort = "Color";
554553

555-
object[] criteria = new object[] { "Red"};
554+
object[] criteria = new object[] { "Red" };
556555

557556
DataRowView[] foundRowsView = view.FindRows(criteria);
558557
// </SnippetLDVFromQueryFindRows>
@@ -648,15 +647,18 @@ orderby product.Field<decimal>("ListPrice")
648647
DataTable productsTable = (DataTable)view.Table;
649648

650649
// Set RowStateFilter to display the current rows.
651-
view.RowStateFilter = DataViewRowState.CurrentRows ;
650+
view.RowStateFilter = DataViewRowState.CurrentRows;
652651

653652
// Query the DataView for red colored products ordered by list price.
654653
var productQuery = from DataRowView rowView in view
655654
where rowView.Row.Field<string>("Color") == "Red"
656655
orderby rowView.Row.Field<decimal>("ListPrice")
657-
select new { Name = rowView.Row.Field<string>("Name"),
658-
Color = rowView.Row.Field<string>("Color"),
659-
Price = rowView.Row.Field<decimal>("ListPrice")};
656+
select new
657+
{
658+
Name = rowView.Row.Field<string>("Name"),
659+
Color = rowView.Row.Field<string>("Color"),
660+
Price = rowView.Row.Field<decimal>("ListPrice")
661+
};
660662

661663
// Bind the query results to another DataGridView.
662664
dataGridView2.DataSource = productQuery.ToList();

0 commit comments

Comments
 (0)