Using Visual Basic.NET for Database Support
❘
385
these fields, you’ll get an error. Consequently, the next section of code displays the mandatory
fields first.
FIgURE 17-23:
Row contains more than just fields.
Notice the
if...else
structures that appear next. Every optional field includes an
IsFieldNameNull()
method. Before you print these optional fields, use the null check, such
as
Row.IsContactNameNull()
, to verify that the field contains data. In this case, the code simply
prints
‘Nothing‘
when the field is null.
You need to consider one other issue when working through your database access methods. Notice
that the
_Region
field has an underscore in front of it. This underscore doesn’t appear in the data-
base or in the Visual Basic.NET code — IronPython adds it for some reason. If you suddenly find
that some fields aren’t accessible, even though you’re using the right name, check for an underscore.
Figure 17-24 shows the output from this example.
FIgURE 17-24:
The extension provides data to IronPython to output.
548592c17.indd 385
2/24/10 12:49:40 PM
www.finebook.ir
386
❘
CHAPTER 17
ExtEnding ironPython Using VisUal Basic.nEt
USINg IRoNPyTHoN CoNSTRUCTIVELy
This chapter has helped you discover the wonders of the Visual Basic.NET extension. As with the
C# extensions discussed in Chapter 16, the extensions described in this chapter follow certain rules
and you must provide basic functionality when creating an extension in Visual Basic.NET before
you can use it with IronPython. Visual Basic.NET extensions also follow the C# extension rules in
areas such as method visibility. The two advanced examples in this chapter help you understand the
areas in which Visual Basic.NET is the better choice when creating an extension.
If you really want to use extensions to their full effect, you really need to know which language
to choose to get the job done quickly. With this in mind, you’ll want to work through all the
examples in this chapter so you understand the Visual Basic.NET strengths. After you complete
the examples, take time to go back through Chapter 16 and the list you created of tasks you might
want to perform for your organization using a combination of IronPython and C#. At this point,
you can ask yourself whether all those tasks really will work best with C# as the extension lan-
guage, or whether they’ll work better using Visual Basic.NET. The whole purpose of this task is
to help you start considering the importance of language choice when designing an application.
Chapter 18 takes you in another direction in working with IronPython — application testing. Some
organizations spend as much time creating a test suite for their application as they do on the appli-
cation itself. The scripting nature of IronPython makes it a perfect choice for some types of testing
tasks. Chapter 18 describes how to perform testing using IronPython as the testing language. It also
helps you understand when you might need to work with another tool to perform testing. Although
IronPython is a great choice, it isn’t the perfect choice for all situations and you need to consider this
issue as part of developing your test suite.
548592c17.indd 386
2/24/10 12:49:40 PM
www.finebook.ir
Do'stlaringiz bilan baham: |