Database Reference
In-Depth Information
OLE DB Type
.NET Type
.NET Typed Accessor
DBTYPE_VARIANT Object
GetValue
DBTYPE_WVARCHAR String
GetString
DBTYPE_WSRT String
GetString
To see typed accessors in action, you'll build a console application that uses them. For this example,
you'll use the Products table from the Northwind database.
Table 14-3 shows the data design of the table. Note that the data types given in the table will be
looked up for their corresponding typed accessor methods in Table 14-1 so you can use them correctly
in your application.
Table 14-3. AdventureWorks Sales.CreditCard Table Data Types
Column Name
Data Type
Length
Allow Nulls?
CreditCardID (unique) int
4
No
nvarchar
CardType
50
No
nvarchar
CardNumber
25
No
tinyint
ExpMonth
1
No
smallint
ExpYear
2
No
datetime
ModifiedDate
8
No
Try It: Using Typed Accessor Methods
In this example, you'll add a Windows form to the DataReader project, and then you will use typed
accessor methods.
1. Select the DataReader project, right-click, and choose Add Windows Form.
From the opened dialog, make sure the Windows form is selected and rename
Form1.cs to TypedAccessor.cs; click OK to add this form to the DataReader
project.
2. Select the TypedAccessor form, and set the Size property's Width to 476 and
Height to 353.
3. Drag a TextBox control to the form and position it toward center of the form.
Select this TextBox control, navigate to the Properties window, and set the
following properties:
Set the Name property to txtTypeAccess.
 
Search WWH ::




Custom Search