Database Reference
In-Depth Information
to appear as:
Application.Run(new TypedAccessor());
7. Build the project, and run it by pressing Ctrl+F5. You should see the results in
Figure 14-6.
Figure 14-6. Using typed accessors
How It Works
You query the Sales.CreditCard table for CardType, CardNumber, ExpMonth, and ExpYear.
// Query
string sql = @"select CardType, CardNumber,ExpMonth,ExpYear from
Sales.CreditCard";
The reason we have you choose these columns is to deal with different kinds of data types and show
how to use relevant typed accessors to obtain the correct results.
// Fetch data
while (rdr.Read())
{
// CardType
txtTypeAccess.AppendText(rdr.GetString(0).PadRight(30));
txtTypeAccess.AppendText("\t");
// CardNumber
txtTypeAccess.AppendText(rdr.GetString(1));
txtTypeAccess.AppendText("\t\t");
 
Search WWH ::




Custom Search