Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Beginning Visual C++ 2005 (2006) [eng]-1

.pdf
Скачиваний:
108
Добавлен:
16.08.2013
Размер:
18.66 Mб
Скачать

Accessing Data Sources in a Windows Forms Application

Summar y

This has been a brief introduction to the capabilities you have for accessing data sources in a Windows Forms application. There’s a great deal more you can do, but you should find that as you now have a good idea of how you use the design capability to assemble controls on a form and how the controls involved in data access work together. You’ll have few problems getting into other areas by yourself.

The key points you have learned about in this chapter include:

A data source can be a relational database, a Web service, or an object.

A class derived from the System::Data::DataSet class is used to encapsulate a data source, and a class derived from the System::Data::DataTable class table encapsulates a table in a data source.

A row of data in a DataTable object is represented by an object of type System::Data::DataRow, and the schema for a column is described by an object of type

System::Data::DataColumn.

A connection to a data source and the commands to access the data are encapsulated in a component called a table adapter.

You use a DataGridView control on a form to display data in the form of a rectangular grid.

You can bind a DataGridView control to a data source to display the contents of a table. You can also use a DataGridView control in unbound mode to display data originating in your program.

You can customize a DataGridView control to modify how rows, columns, headers and individual cells are displayed.

A BindingSource component provides an interface between a data source and controls on a form. A BindingSource component can link the columns in a table to individual controls on a form, or it can link the contents of a table to a DataGridView control.

A BindingNavigator control provides a toolbar for navigating data that you access via a

BindingSource component.

Exercises

You can download the source code for the examples in the book and the solutions to the following exercises from http://www.wrox.com.

1.Modify Ex22_04 so that the column headers are displayed in a 12-point italic font.

2.Modify Ex22_05 so the columns are wide enough to accommodate the text in each cell.

3.Modify Ex22_05 so that alternate rows of data on each tab page appear shaded.

4.Create a Windows Forms application that displays the Suppliers table from the Northwind database.

1129

A

C++ Keywords

Keywords have been assigned special significance within the C++ language, so you must not use them as names within your programs. The Visual C++ 2005 compiler compiles programs written in ISO/ANSI C++ and programs written for the CLR that conform to the C++/CLI specification, so the compiler recognizes the set of keywords defined by ISO/ANSI C++ as well as the additional set of keywords defined by C++/CLI. Although programming in native C++, you need be concerned only with the ISO/ANSI C++ keywords. When writing programs for the CLR, you need to be aware of both sets of keywords.

ISO/ANSI C++ Keywords

The ISO/ANSI C++ language specification defines the following keywords:

asm

false

sizeof

auto

float

static

bool

for

static_cast

break

friend

struct

case

goto

switch

catch

if

template

char

inline

this

class

int

throw

const

long

true

const_cast

mutable

try

continue

namespace

typedef

 

 

 

Table continued on following page

Appendix A

default

new

typeid

delete

operator

typename

do

private

union

double

protected

unsigned

dynamic_cast

public

using

else

register

virtual

enum

reinterpret_cast

void

explicit

return

volatile

export

short

wchar_t

extern

signed

while

 

 

 

C++/CLI Keywords

The C++/CLI language specification defines the following keywords in addition to those defined for ISO/ANSI C++:

enum class

enum struct

for each

gcnew

interface class

interface struct

nullptr

ref class

ref struct

value class

value struct

 

Note that the word pairs are keywords, not necessarily the individual words; for example, for each is a keyword, but each is not.

The C++/CLI language also defines a number of identifiers that are not keywords but have a contextsensitive meaning in some circumstances. These are:

abstract

delegate

event

finally

generic

in

initonly

internal

literal

override

property

sealed

where

 

 

 

In principle you can still use these identifiers as names in your code because the context determines when they have special significance, but I recommend that you treat them as keywords and do not use them for other purposes. In that way you avoid any possibility for confusion on the part of someone else who may be reading your code.

1132

B

ASCII Codes

The first 32 ASCII (American Standard Code for Information Interchange) characters provide control functions. In the following table, only the first 128 ASCII characters have been included. The remaining 128 characters include further special symbols and letters for national character sets, so there are many varieties of these to suit a wide range of language contexts.

Decimal

Hexadecimal

Character

Control

 

 

 

 

000

00

null

NUL

001

01

J

SOH

002

02

STX

003

03

ETX

004

04

EOT

005

05

ENQ

006

06

ACK

007

07

BEL (Audible bell)

008

08

 

Backspace

009

09

 

HT

010

0A

 

LF (Line feed)

011

0B

 

VT (Vertical tab)

012

0C

 

FF (Form feed)

013

0D

 

CR (Carriage return)

014

0E

 

SO

015

0F

¤

SI

 

 

 

 

Table continued on following page

Appendix B

Decimal

Hexadecimal

016

10

017

11

018

12

019

13

020

14

021

15

022

16

023

17

024

18

025

19

026

1A

027

1B

028

1C

029

1D

030

1E

031

1F

032

20

033

21

034

22

035

23

036

24

037

25

038

26

039

27

040

28

041

29

042

2A

043

2B

044

2C

045

2D

046

2E

Character

\

!

#

$

%

&

(

)

*

+

,

-

.

Control

DLE

DC1

DC2

DC3

DC4

NAK

SYN

ETB

CAN

EM

SUB

ESC (Escape)

FS

GS

RS

US

space

1134

ASCII Codes

Decimal

Hexadecimal

Character

Control

 

 

 

 

047

2F

/

 

048

30

0

 

049

31

1

 

050

32

2

 

051

33

3

 

052

34

4

 

053

35

5

 

054

36

6

 

055

37

7

 

056

38

8

 

057

39

9

 

058

3A

:

 

059

3B

;

 

060

3C

<

 

061

3D

=

 

062

3E

>

 

063

3F

?

 

064

40

@

 

065

41

A

 

066

42

B

 

067

43

C

 

068

44

D

 

069

45

E

 

070

46

F

 

071

47

G

 

072

48

H

 

073

49

I

 

074

4A

J

 

075

4B

K

 

076

4C

L

 

077

4D

M

 

 

 

 

 

Table continued on following page

1135

Appendix B

Decimal

Hexadecimal

Character

Control

 

 

 

 

078

4E

N

 

079

4F

O

 

080

50

P

 

081

51

Q

 

082

52

R

 

083

53

S

 

084

54

T

 

085

55

U

 

086

56

V

 

087

57

W

 

088

58

X

 

089

59

Y

 

090

5A

Z

 

091

5B

[

 

092

5C

\

 

093

5D

]

 

094

5E

^

 

095

5F

_

 

096

60

 

097

61

a

 

098

62

b

 

099

63

c

 

100

64

d

 

101

65

e

 

102

66

f

 

103

67

g

 

104

68

h

 

105

69

i

 

106

6A

j

 

107

6B

k

 

108

6C

l

 

 

 

 

 

1136

ASCII Codes

Decimal

Hexadecimal

Character

Control

 

 

 

 

109

6D

m

 

110

6E

n

 

111

6F

o

 

112

70

p

 

113

71

q

 

114

72

r

 

115

73

s

 

116

74

t

 

117

75

u

 

118

76

v

 

119

77

w

 

120

78

x

 

121

79

y

 

122

7A

z

 

123

7B

{

 

124

7C

|

 

125

7D

}

 

126

7E

~

 

127

7F

delete

 

 

 

 

 

The Unicode codes that have the same numerical code values as the ASCII codes in the table represent the same characters. You’ll find comprehensive information on the Unicode character coding system at http://www.unicode.org.

1137