1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . ComponentModel ;
4
3
using System . Data ;
5
- using System . Data . SqlClient ;
6
- using System . Data . Common ;
7
- using System . Drawing ;
4
+ using System . Globalization ;
8
5
using System . Linq ;
9
6
using System . Text ;
10
7
using System . Windows . Forms ;
11
- using System . Globalization ;
8
+ using Microsoft . Data . SqlClient ;
12
9
13
10
namespace DataViewSamples
14
11
{
@@ -84,14 +81,14 @@ private void FillDataSet(DataSet ds)
84
81
// Add data relations.
85
82
DataTable orderHeader = ds . Tables [ "SalesOrderHeader" ] ;
86
83
DataTable orderDetail = ds . Tables [ "SalesOrderDetail" ] ;
87
- DataRelation order = new DataRelation ( "SalesOrderHeaderDetail" ,
84
+ DataRelation order = new ( "SalesOrderHeaderDetail" ,
88
85
orderHeader . Columns [ "SalesOrderID" ] ,
89
86
orderDetail . Columns [ "SalesOrderID" ] , true ) ;
90
87
ds . Relations . Add ( order ) ;
91
88
92
89
DataTable contact = ds . Tables [ "Contact" ] ;
93
90
DataTable orderHeader2 = ds . Tables [ "SalesOrderHeader" ] ;
94
- DataRelation orderContact = new DataRelation ( "SalesOrderContact" ,
91
+ DataRelation orderContact = new ( "SalesOrderContact" ,
95
92
contact . Columns [ "ContactID" ] ,
96
93
orderHeader2 . Columns [ "ContactID" ] , true ) ;
97
94
ds . Relations . Add ( orderContact ) ;
@@ -113,14 +110,16 @@ static private string SoundEx(string word)
113
110
if ( size > 1 )
114
111
{
115
112
// Convert the word to uppercase characters.
116
- word = word . ToUpper ( System . Globalization . CultureInfo . InvariantCulture ) ;
113
+ word = word . ToUpper ( CultureInfo . InvariantCulture ) ;
117
114
118
115
// Convert the word to a character array.
119
116
char [ ] chars = word . ToCharArray ( ) ;
120
117
121
118
// Buffer to hold the character codes.
122
- StringBuilder buffer = new StringBuilder ( ) ;
123
- buffer . Length = 0 ;
119
+ StringBuilder buffer = new ( )
120
+ {
121
+ Length = 0
122
+ } ;
124
123
125
124
// The current and previous character codes.
126
125
int prevCode = 0 ;
@@ -227,8 +226,8 @@ private void button2_Click(object sender, EventArgs e)
227
226
228
227
EnumerableRowCollection < DataRow > query =
229
228
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 )
232
231
select order ;
233
232
234
233
DataView view = query . AsDataView ( ) ;
@@ -471,7 +470,7 @@ where contact.Field<string>("LastName") == "Hernandez"
471
470
bindingSource1 . DataSource = view ;
472
471
dataGridView1 . AutoResizeColumns ( ) ;
473
472
474
- // </SnippetLDVFromQueryWhere2>
473
+ // </SnippetLDVFromQueryWhere2>
475
474
}
476
475
477
476
private void button18_Click ( object sender , EventArgs e )
@@ -552,7 +551,7 @@ orderby product.Field<Decimal>("ListPrice"), product.Field<string>("Color")
552
551
553
552
view . Sort = "Color" ;
554
553
555
- object [ ] criteria = new object [ ] { "Red" } ;
554
+ object [ ] criteria = new object [ ] { "Red" } ;
556
555
557
556
DataRowView [ ] foundRowsView = view . FindRows ( criteria ) ;
558
557
// </SnippetLDVFromQueryFindRows>
@@ -648,15 +647,18 @@ orderby product.Field<decimal>("ListPrice")
648
647
DataTable productsTable = ( DataTable ) view . Table ;
649
648
650
649
// Set RowStateFilter to display the current rows.
651
- view . RowStateFilter = DataViewRowState . CurrentRows ;
650
+ view . RowStateFilter = DataViewRowState . CurrentRows ;
652
651
653
652
// Query the DataView for red colored products ordered by list price.
654
653
var productQuery = from DataRowView rowView in view
655
654
where rowView . Row . Field < string > ( "Color" ) == "Red"
656
655
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
+ } ;
660
662
661
663
// Bind the query results to another DataGridView.
662
664
dataGridView2 . DataSource = productQuery . ToList ( ) ;
0 commit comments