Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 50 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
50
Dung lượng
1,46 MB
Nội dung
4.9 C# 3.0 Language Enhancement for LINQ 223
tion of compositional APIs that have equal expressive power of query languages in
domains such as relational databases and XML.
Compared with C# 2.0, signifi cant enhancements have been added into C# 3.0, and
these enhancements are mainly developed to support the Language - Integrated Query.
LINQ is a series of language extensions that supports data querying in a type - safe way; it
is released with the latest version Visual Studio, Visual Studio.NET 2008. The data to be
queried, which we have discussed in the previous sections in this chapter, can take the
form of objects (LINQ to Objects), databases (LINQ - enabled ADO.NET, which includes
LINQ to SQL, LINQ to DataSet, and LINQ to Entities), XML (LINQ to XML), and
so on.
In addition to those general LINQ topics, special improvements on LINQ are
made for C# and involved in C# 3.0. The main components of these improvements
include:
• Lambda expressions
• Extension methods
• Implicitly typed local variables
• Query expressions
Let ’ s have a detailed discussion of these topics one by one.
4.9.1 Lambda Expressions
Lambda expressions are a language feature that is similar in many ways to anonymous
methods. In fact, if lambda expressions had been developed and implemented into the
language fi rst, there would have been no need for anonymous methods. The basic idea
of using lambda expressions is that you can treat code as data. In the early version C#,
such as C# 1.0, it is very common to pass strings, integers, reference types, and so on to
methods so that the methods can work on those values. Anonymous methods and lambda
expressions extend the range of the values to include code blocks. This concept is common
in functional programming.
The syntax of lambda expressions can be expressed as a comma - delimited list of
parameters with the lambda operator (= > ) followed by an expression. For more compli-
cated lambda expressions, a statement block can be followed after the lambda operator.
A simple example of lambda expression used in C# looks like:
x = > y
foreach (var fi in facultyUpdates.Elements("facultyUpdate"))
{
Faculty faculty = db.Faculties.
First(f => f.faculty_id == (string)fi.Element("faculty_id"));
faculty.Phone = (string)fi.Element("phone");
}
db.SubmitChanges();
Figure 4.67 Piece of sample code to read and update database.
c04.indd 223c04.indd 223 2/11/2010 11:52:26 AM2/11/2010 11:52:26 AM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
224 Chapter 4 Introduction to Language-Integrated Query (LINQ)
where x on the left side of the lambda operator is the input parameter and the y on the
right side of the lambda operator is the output parameter. The data type of both the input
and the output parameters should be explicitly indicated by the delegate. Therefore the
lambda expressions are closely related to delegate. This lambda expression can be read
as input x and output y . The syntax of this kind of simple lambda expressions can be
written as:
(param1, param2, … . paramN) = > output
A parenthesis should be used to cover all input parameters.
For more complicated lambda expressions, a statement block should be adopted. An
example of this kind of syntax is shown below:
(x, y) = > { if (x > y) return x; else return y; }
Note that the data type of both the input and the output parameters must be identical
with those types defi ned in the delegate. For example, in the previous sample expression
x = > y, if the input x is defi ned as a string, and the output is defi ned as an integer by the
delegate, the output must be converted to an integer type by using the following lambda
expression:
x = > y.Length
where Length is a method to convert the input from a string to an integer.
Another example of using lambda expressions to perform LINQ query is:
IEnumerable < Faculty > faculty =
EnumerableExtensions.Where(faculties, f = > f.faculty_name ==
“Ying Bai”);
Here the SQO method Where() is used as a fi lter in this query. The input is an object
with a type of faculties, and the output is a string variable. The compiler is able to infer that
“ f ” refers to a faculty because the fi rst parameter of the Where() method is
IEnumerable< Faculty > , such that T must, in fact, be Faculty . Using this knowledge,
the compiler also verifi es that Faculty has a faculty_name member. Finally, there is no
return key word specifi ed. In the syntactic form, the return member is omitted but this is
merely syntactic convenience. The result of the expression is still considered to be the
return value.
Lambda expressions also support a more verbose syntax that allows you to specify
the types explicitly, as well as execute multiple statements. An example of this kind of
syntax is:
return EnumerableExtensions.Where(faculties, (Faculty f) = >
{string id =faculty_id; return f.faculty_id = id;});
Here the EnumerableExtensions class is used to allow us to access and use the static
method Where() since all SQO methods are static methods defi ned in either Enumerable
or Queryable classes. As you know, a static method is defi ned as a class method and can
be accessed and used by each class in which that method is defi ned. Is that possible
for us to access a static method from an instance of that class? Generally, this will be
considered as a stupid question since that is impossible. Is there any way to make it pos-
c04.indd 224c04.indd 224 2/11/2010 11:52:26 AM2/11/2010 11:52:26 AM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
4.9 C# 3.0 Language Enhancement for LINQ 225
sible? The answer is maybe. To get that question answered correctly, let ’ s go to the
next topic.
4.9.2 Extension Methods
Regularly, static methods can only be accessed and used by classes in which those static
methods are defi ned. For example, all SQO methods, as we discussed in Sections 4.1.3
and 4.1.4 , are static methods defi ned in either Enumerable or Queryable classes and can
be accessed by those classes directly. But those static methods cannot be accessed by any
instance of those classes. Let ’ s use an example to make this story clear.
Figure 4.68 shows a piece of code that defi nes both class and instance methods.
In this example, the method ConvertToUpper() is an instance method and
ConvertToLower() is a class method. To call these methods, different calling strategy
must be utilized. To call and execute the instance method ConvertToUpper(), one must
fi rst create a new instance of the class Conversion, and then call that method. To call and
execute the class method ConvertToLower(), one can directly call it with the class name
prefi xed in front of that method. Figure 4.69 shows a piece of code to call these two
methods.
In some situations, the query would become very complicated if one wants to call
those static methods from any instance of those classes. To solve this complex issue,
extension methods are developed to simplify the query structures and syntax.
To declare an extension method from existing static method, just add the keyword
this to the fi rst argument of that static method. For example, to make the class method
public static class Convertion
{
public string ConvertToUpper(string input)
{
return input.ToUpper();
}
public static string ConvertToLower(string input)
{
return input.ToLower();
}
}
Figure 4.68 Example of defi ning class and instance method.
// call instance method ConvertToUpper.
// first create a new instance of the class Conversion
Conversion conv = new Conversion();
string instResult = conv.ConvertToUpper(“conversion”);
// call class method ConvertToLower.
string classResult = Conversion.ConvertToLower(“CONVERSION”);
Figure 4.69 Example of calling class and instance method.
c04.indd 225c04.indd 225 2/11/2010 5:16:05 PM2/11/2010 5:16:05 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
226 Chapter 4 Introduction to Language-Integrated Query (LINQ)
ConvertToLower() an extension method, add the keyword this to the fi rst argument of
that method, as shown in Figure 4.70 .
Now the class method ConvertToLower() has been converted to an extension method
and can be accessed by any instance of the class Conversion.
The extension methods have the following important properties:
1. The extension method will work as an instance method of any object with the same type
as the extension method ’ s fi rst argument ’ s data type.
2. The extension methods can only be declared in static classes.
3. Both the class and the extension method are prefi xed by the keyword static .
Refer to Figure 4.70 . The extension method ConvertToLower() has a data type of
string since the fi rst argument ’ s type is string. This method is declared in a static class
Conversion, and both class and this method are prefi xed by the keyword static .
4.9.3 Implicitly Typed Local Variables
In LINQ query, there ’ s another language feature known as implicitly typed local variables
(or var for short) that instructs the compiler to infer the type of a local variable. As you
know, with the addition of anonymous types to C#, a new problem becomes a main
concern, which is that if a variable is being instantiated that is an unnamed type, as in an
anonymous type, what type variable would you assign it to? LINQ queries belong to
strongly typed queries with two popular types: IEnumerable < T > and IQueryable < T > , as
we discussed at the beginning of this chapter. Figure 4.71 shows an example of this kind
of variable with an anonymous type.
A compiling error will be encountered when this piece of code is compiled since the
data type of the variable faculty is not indicated. In C# 3.0 language enhancement for
public static class Convertion
{
// declare the class method ConvertToLower to extension method.
public static string ConvertToLower(this string input)
{
return input.ToLower();
}
}
Figure 4.70 Declare the class method ConvertToLower to extension method.
public static class Main()
{
// declare an anonymous type variable.
faculty = new { faculty_id = “B78880”, faculty_name = “Ying Bai” };
Console.WriteLine(“faculty information {0}, {1}”, faculty.faculty_id + “. “ + faculty.faculty_name);
}
Figure 4.71 Declare an anonymous type variable.
c04.indd 226c04.indd 226 2/11/2010 5:16:05 PM2/11/2010 5:16:05 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
4.9 C# 3.0 Language Enhancement for LINQ 227
LINQ, a new terminology, implicitly typed local variable var , is developed to solve this
kind of anonymous type problem. Refer to Figure 4.72 , where the code written in Figure
4.71 is rewritten.
This time there would be no error if you compile this piece of code since the keyword
var informs the compiler to implicitly infer the variable type from the variable ’ s initializer.
In this example, the initializer for this implicitly typed variable faculty is a string collec-
tion. This means that all implicitly typed local variables are statically type checked at the
compile time, therefore an initializer is required to allow the compiler to implicitly infer
the type from it.
The implicitly typed local variables mean that those variables are just local within a
method, for example, the faculty is valid only inside the main() method in the previous
example. It is impossible for them to escape the boundaries of a method, property,
indexer, or other block because the type cannot be explicitly stated, and var is not legal
for fi elds or parameter types.
Another important terminology applied in C# 3.0 language enhancement for LINQ
is the object initializers. Object initializers basically allow the assignment of multiple
properties or fi elds in a single expression. For example, a common pattern for object
creation is shown in Figure 4.73 .
In this example, there is no constructor of Faculty that takes a faculty id, name, offi ce,
and title; however, there are four properties, faculty_id, faculty_name, offi ce, and title,
which can be set once an instance faculty is created. Object initializers allow to create a
new instance with all necessary initializations being performed at the same time as the
instantiation process.
4.9.4 Query Expressions
To perform any kind of LINQ query, such as LINQ to Objects, LINQ to ADO.NET, or
LINQ to XML, a valid query expression is needed. The query expressions implemented
in C# 3.0 have a syntax that is closer to SQL statements and are composed of some
clauses. One of the most popular query expressions is the foreach statement. As this
public static class Main()
{
// declare an anonymous type variable.
var faculty = new { faculty_id = “B78880”, faculty_name = “Ying Bai” };
Console.WriteLine(“faculty information {0}, {1}”, faculty.faculty_id + “. “ + faculty.faculty_name);
}
Figure 4.72 Declare an anonymous type variable using implicitly typed local variable.
Faculty faculty = new Faculty();
faculty.faculty_id = “B78880”;
faculty.faculty_name = “Ying Bai”;
faculty.office = “MTC-211”;
faculty.title = “Associate Professor”;
Figure 4.73 Example of using the object initializer.
c04.indd 227c04.indd 227 2/11/2010 11:52:27 AM2/11/2010 11:52:27 AM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
228 Chapter 4 Introduction to Language-Integrated Query (LINQ)
foreach is executed, the compiler converts it into a loop with calls to methods such as
GetEnumerator() and MoveNext(). The main advantage of using the foreach loop to
perform the query is that it provides a signifi cant simplicity in enumerating through
arrays, sequences, and collections and return the terminal results in an easy way. A typical
syntax of query expression is shown in Figure 4.74 .
Generally, a query expression is composed of two blocks. The top block in Figure
4.74 is the from - clause block and the bottom block is the query - body block. The from -
clause block only takes charge of the data query information (no query results), but the
query - body block performs the real query and contains the real query results.
Referring to syntax represented in Figure 4.74 , the following components should be
included in a query expression:
• A query variable must be defi ned fi rst in either explicitly (IEnumerable < T > ) or implicitly (var).
• A query expression can be represented in either query syntax or method syntax.
• A query expression must start with a from clause, and must end with a select or group clause.
Between the fi rst from clause and the last select or group clause, it can contain one or more
of these optional clauses: where , orderby , join , let , and even additional from clauses.
In all LINQ queries (including LINQ to DataSet), all of clauses will be converted to
the associated SQO methods, such as From(), Where(), OrderBy(), Join(), Let(), and
Select(), as the queries are compiled. Refer to Table 4.1 to get the most often used
Standard Query Operators and their defi nitions.
In LINQ, a query variable is always strongly typed, and it can be any variable that
stores a query instead of the results of a query. More specifi cally, a query variable is
always an enumerable type that will produce a sequence of elements when it is iterated
over in a foreach loop or a direct call to its method IEnumerator.MoveNext.
A very detailed discussion about the query expression has been provided in Sections
4.5.1.1 and 4.5.1.2 in this Chapter. Refer to those sections to get more details on this topic.
Before we can fi nish this chapter, a real query example implemented in our project
is shown in Figure 4.75 .
4.10 CHAPTER SUMMARY
Language - Integrated Query (LINQ), which is built on .NET Frameworks 3.5, is a new
technology released withVisual Studio.NET 2008 by Microsoft. LINQ is designed to
var query_variable = from [identifier] in [data source]
let [expression]
where [boolean expression]
order by [[expression](ascending/descending)], [optionally repeat]
select [expression]
group [expression] by [expression] into [expression]
foreach (var range_variable in query_variable)
{
//pick up or retrieve back each element from the range_variable….
}
Figure 4.74 Typical syntax of query expression.
c04.indd 228c04.indd 228 2/11/2010 11:52:27 AM2/11/2010 11:52:27 AM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
4.10 Chapter Summary 229
query general data sources represented in different formats, such as Objects, DataSet,
SQL Server database, Entities, and XML. The innovation of LINQ bridges the gap
between the world of objects and the world of data.
An introduction to LINQ general programming guide is provided in the fi rst part
of this chapter. Some popular interfaces widely used in LINQ, such as IEnumerable,
IEnumerable < T > , IQueryable, and IQueryable < T > , and Standard Query Operators
(SQO) including the deferred and nondeferred SQO, are discussed in that part.
An introduction to LINQ Query is given in the second section in this chapter.
Following this introduction, a detailed discussion and analysis about LINQ implemented
for different data sources is provided based on the sequence listed below.
1. Architecture and components of LINQ
2. LINQ to Objects
3. LINQ to DataSet
4. LINQ to SQL
5. LINQ to Entities
6. LINQ to XML
7. C# 3.0 language enhancement for LINQ
Both literal introductions and actual examples are provided for each part listed above
to give readers not only a general and global picture about LINQ technique applied for
different data, but also practical and real feeling about the program codes developed to
realize the desired functionalities.
Twelve real projects are provided in this chapter to help readers to understand and
follow up on all techniques discussed in this chapter.
After fi nishing this chapter, readers should be able to:
• Understand the basic architecture and components implemented in LINQ.
• Understand the functionalities of Standard Query Operators.
• Understand general interfaces implemented in LINQ, such as LINQ to Objects, LINQ to
DataSet, LINQ to SQL, LINQ to Entities, and LINQ to XML.
• Understand the C# 3.0 language enhancement for LINQ.
• Design and build real applications to apply LINQ queries to perform data actions to all
different data sources.
static void Main()
{
IEnumerable<Faculty> faculty = db.Faculties.Where(f => f.faculty_id == "D.*",
f => f.college == “U.*”,
f => f.title == “Associate Professor”);
// Execute the query to produce the results
foreach (Faculty fi in faculty)
{
Console.WriteLine("{0}\n{1}\n{2}\n{3}\n{4}", f.faculty_name, f.title, f.office, f.phone, f.email);
}
}
Figure 4.75 Real example of query expression.
c04.indd 229c04.indd 229 2/11/2010 11:52:27 AM2/11/2010 11:52:27 AM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
230 Chapter 4 Introduction to Language-Integrated Query (LINQ)
• Develop and build applications to apply C# 3.0 language enhancement for LINQ to perform
all different queries to data sources.
Starting with the next chapter, we will concentrate on the databaseprogramming
with Visual C#.NET using real projects.
HOMEWORK
I. True/False Selections
____ 1. LINQ queries are built based on. NET Frameworks 3.5.
____ 2. Most popular interfaces used for LINQ queries are IEnumerable, IEnumerable < T > ,
IQueryable, and IQueryable < T > .
____ 3. IEnumerable interface is used to convert data type of data source to IEnumerable < T > ,
which can be implemented by LINQ queries.
____ 4. IEnumerable interface is inherited from the class IQueryable.
____ 5. All Standard Query Operator methods are static methods defi ned in the IEnumerable
class.
____ 6. IEnumerable and IQueryable interfaces are mainly used for the nongeneric collections
supported by the earlier versions of C#, such as C# 1.0 or earlier.
____ 7. All LINQ query expressions can only be represented as query syntax.
____ 8. All LINQ query expressions will be converted to the Standard Query Operator methods
during the compile time by CLR.
____ 9. The query variable used in LINQ queries contains both the query information and the
returned query results.____
___ 10. LINQ to SQL, LINQ to DataSet, and LINQ to Entities belong to LINQ to ADO.NET.
II. Multiple Choices
1. The difference between the interfaces IEnumerable and IEnumerable < T > is that the former is
mainly used for ______, but the latter is used for _______.
a. Nongeneric collections, generic collections
b. Generic collections, nongeneric collections
c. All collections, partial collections
d. .NET Frameworks 2.0,. NET Frameworks 3.5
2. The query variable used in LINQ queries contains ________.
a. Query information and query results
b. Query information
c. Query results
d. Standard Query Operator
3. All Standard Query Operator (SQO) methods are defi ned as _______; this means that these
methods can be called either as class methods or as instance methods.
a. Class methods
b. Instance methods
c. Variable methods
d. Extension methods
c04.indd 230c04.indd 230 2/11/2010 11:52:27 AM2/11/2010 11:52:27 AM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Homework 231
4. One of the SQO methods, the AsEnumerable() operator method, is used to convert the data
type of the input object from _______ to _______.
a. IQuerable < T > , IEnumrable < T >
b. IEnumerable < T > , IEnumerable < T >
c. Any, IEnumerable < T >
d. All of the above
5. LINQ to Objects is used to query any sequences or collections that are either explicitly or
implicitly compatible with _________ sequences or ________ collections.
a. IQuerable, IQuerable < T >
b. IEnumerable, IENumerable < T >
c. Deferred SQO, non - deferred SQO
d. Generic, nongeneric
6. LINQ to DataSet is built on the _________ architecture. The codes developed by using that
version of ADO.NET will continue to function in a LINQ to DataSet application without
modifi cations.
a. ADO.NET 2.0
b. ADO.NET 3.0
c. ADO.NET 3.5
d. ADO.NET 4.0
7. Two popular LINQ to SQL Tools, ________ and _______, are widely used in developing appli-
cations of using LINQ to SQL.
a. Entity Data Model, Entity Data Model Designer
b. IEnumerable, IEnumerable < T >
c. SQLMetal, Object Relational Designer
d. IQueryable, IQueryable < T >
8. LINQ to SQL query is performed on classes that implement the _________ interface. Since the
________ interface is inherited from the ________ with additional components, therefore the
LINQ to SQL queries have additional query operators.
a. IEnumerable < T > , IEnumerable < T > , IQueryable < T >
b. IEnumerable < T > , IQueryable < T > , IEnumerable
< T >
c. IQueryable < T > , IEnumerable
< T > , IQueryable < T >
d. IQueryable < T > , IQueryable < T > , IEnumerable < T >
9. LINQ to Entities queries are performed under the control of the ___________ and the
__________.
a. .NET Frameworks 3.5, ADO.NET 3.5
b. ADO.NET 3.5 Entity Framework, ADO.NET 3.5 Entity Framework Tools
c. IEnumerable < T > , IQueryable < T >
d. Entity Data Model, Entity Data Model Designer
10. To access and implement ADO.NET 3.5 EF and ADO.NET 3.5 EFT, developers need to
understand the ____________, which is a core of ADO.NET 3.5 EF.
a. SQLMetal
b. Object Relational Designer
c. Generic collections
d. Entity Data Model
c04.indd 231c04.indd 231 2/11/2010 11:52:27 AM2/11/2010 11:52:27 AM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
232 Chapter 4 Introduction to Language-Integrated Query (LINQ)
11. Lambda expressions, which are represented by ________, are a language feature that is similar
in many ways to _________ methods.
a. = > , Standard Query Operator
b. = > , anonymous
c. = > , Generic collection
d. = > , IQuerable
12. Extension methods are defi ned as those methods that can be called as either ________ methods
or ___________ methods.
a. Class, instance
b. IEnumerable < T > , IQueryable < T >
c. Generic, nongeneric
d. Static, dynamic
13. In LINQ queries, the data type var is used to defi ne a(n) ____________, and the real data type
of that variable can be inferred by the __________ during the compiling time.
a. Generic variable, debugger
b. Implicitly typed local variable, compiler
c. Nongeneric variable, builder
d. IEnumerable < T > variable, loader
14. In LINQ queries, the query expression must start with a ________ clause, and must end with
a ___________ or _________ clause.
a. begin, select, end
b. select, where, orderby
c. from, select, group
d. query variable, range variable, foreach loop
15. The DataContext is a class that is used to establish a ________ between your project and your
database. In addition to this role, the DataContext also provides the function to _______ opera-
tions of the Standard Query Operators to the SQL statements that can be run in real
databases.
a. Relationship, perform
b. Reference, translate
c. Generic collections, transform
d. Connection, convert
III. Exercises
1. Explain the architecture and components of LINQ, and illustrate the functionality of these
using a block diagram.
2. Explain the execution process of a LINQ query using the foreach statement.
3. Explain the defi nitions and functionalities of the Standard Query Operator methods.
4. Explain the relationship between the LINQ query expressions and Standard Query Operator
methods
5. Explain the defi
nitions and functionalities of IEnumerable, IEnumerable < T > ,
IQueryable, and
IQueryable< T > interfaces.
6. Explain the components and procedure used to performe LINQ to SQL queries.
c04.indd 232c04.indd 232 2/11/2010 11:52:27 AM2/11/2010 11:52:27 AM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
[...]... features, one of the most important features added by Visual Studio 2008 is the LINQ for the database access and data source applications Because of that, Visual Studio.NET 2008 greatly reduces the programming load and the number of query program codes to provide significant assistance to people who are new to database programmingwithVisual Studio Starting from Visual Studio 2005, Microsoft provides quite... database programming easily and efficiently The most popular design tools and wizards are: • Data Components in the Toolbox Window • Wizards in the Data Source Window These design tools and wizards are still implemented in Visual Studio 2008, and they can be accessed and used by any NET-compatible programming language such as Visual C++, Visual Basic, Visual J#, and Visual C# The Toolbox window in Visual. .. build simple database applications without needing to touch very complicated coding issues Combine these data components with wizards, which are located in the Data Source wizard and related to ADO.NET, and one can easily develop binding relationships between the data source and controls on the Visual C# windows form object Furthermore one can build simple Practical Database ProgrammingWithVisual C#.NET,... Selection Query withVisual C#.NET Visual C# project to navigate, scan, retrieve, and manipulate data stored in the data source with a few lines of codes This chapter is divided to two parts: Part I provides a detailed description and discussion on how to use Visual Studio 2008 tools and wizards to build simple but efficient database applications without touching complicated coding in the Visual C# environment... the LINQ to DataSet queries Chapter 5 Data Selection Query withVisual C#.NET Compared to Visual Studio 2005, Visual Studio 2008 adds more new components to simplify data accessing, inserting, and updating functionalities for database development and applications First of all, Visual Studio 2005 was built based on the NET Framework 2.0, but Visual Studio 2008 is based on NET Framework 3.5 Quite a number... Server database and a SQL Server database file is that the former is a complete database that integrates the database management system with data tables to form a body or a package, but the latter is only a database file The second option, Web Service, enables you to select a data source that is located at a Web service The third option, Object, allows you to bind your user interface to one of your own database. .. such as the fundamentals of databases, which was introduced in Chapter 2, and ADO.NET, which was discussed in Chapter 3 Also three sample databases developed in Chapter 2, which are CSE_DEPT.accdb, CSE_DEPT.mdf, and CSE_DEPT of the Oracle Database 10g, will be used through this chapter PART I DATA QUERY WITHVISUAL STUDIO DESIGN TOOLS AND WIZARDS Before we consider the Visual Studio 2008 tools and... project Let’s begin to develop this sample project with five forms 5.3.1.1 LogIn Form First, create a new Visual C# 2008 project with the name SelectWizard Open Visual Studio 2008 and go to the File|New|Project item to open the New Project window In the Project types pane, expand the Visual C# item and make sure that you select the Windows item under the Visual C# item Select the Windows Forms Application... they are: 5.3 Build a Sample Database Project—SelectWizard with SQL Server Database Figure 5.17 Finished New Project window Figure 5.18 Create a new project window 253 254 Chapter 5 Data Selection Query withVisual C#.NET • Windows Form Designing window: Contains Windows Form object and File Form object • Toolbox window: Contains all tools and components to be used to develop Visual C# projects • Solution... Selection Query withVisual C#.NET • Automatically supports visual styles on Windows XP and the Windows Server 2003 family when the EnableVisualStyles method is called from the application’s Main method Refer to Figure 5.6 to get a relationship between the DataGridView and other data components A more detailed description on how to use the DataGridView control to bind and display data in Visual C# will .
and controls on the Visual C# windows form object. Furthermore one can build simple
Practical Database Programming With Visual C#. NET, by Ying Bai
Copyright. Data Selection Query with Visual C#. NET
Visual C# project to navigate, scan, retrieve, and manipulate data stored in the data
source with a few lines of