Wednesday, April 9, 2008

TableAdapters

TableAdapters allow you to get data from a DataSet. You use DataSets to connect to a database and retrieve table schema information. Then when you want to get the data you use the table's TableAdapter.
TableAdapters are nothing more than classes with methods that you can create visually through a designer. The methods are sql queries.
So if you want to get a populated table you call one of these two premade methods.
MessageTableAdapter adapter = new MessageTableAdapter(); 
Message messageDataTable = adapter.GetData(); 
TableAdapters will:
  • Open a connection.
  • Query for the data.
  • Return the data in the table schema it is attached to.
  • Close the connection.

You can create as many methods as you want on the TableAdapter to:

  • Insert
  • Update
  • Delete
  • Select

More Info: MSDN: TableAdapter Overview