Okay, so I'm not a fan of drag-and-drop (D&D). While the code generation behind the scenes is far more sophisticated than ever before, it often adds a lot of overhead to the Form that I simply don't need or want. So, how can you use these TableAdapter classes without dragging it on the Form and having to deal with all of the...ah, "stuff" that gets added to the form? Once you've created a TableAdapter, it's exposed there in the Data Sources window. If you look closely at the Data Sources window, you'll see two different icons, as shown in Figure 6.40. Figure 6.40. A populated Data Sources window with two TableAdapters.
The reason I'm mentioning this is that these names can help you remember the right naming conventions to instantiate and reference the objects. Running the Data Sourcegenerated strongly typed TableAdapter Fill or GetData methods is easy if you know the object class hierarchy. The TableAdapter is a member of the DataSet.TableAdapters collection. Each specifically referenced TableAdapter exposes a Fill method, a GetData method, and/or any number of custom methods. To make things a bit more difficult (but more flexible), each of these methods can be named just about anything. You might have to revisit the Data Source Designer to see how they have been designed. So, how does this look in code? Take a look at Figure 6.41. Notice how I instantiate a new instance of the named DataSet's AuthorsTableAdapter and execute its Fill and GetData methods to return or populate either an untyped DataTable instance or a strongly typed AuthorsDataTable instance. Figure 6.41. Addressing strongly typed TableAdapter and DataTable instances. |