Datasqltypes provides classes for native sql server

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Adapter Interface Populates or sends updates to a DataSet Implemented by OleDbDataAdapter and SqlDataAdapter Not connection based Represents an asynchronous approach A superset of a command object Contains four default command objects for Select, Insert, Update, and Delete ADO.NET Classes DataSet DataSet Example string sConnString = “Persist Security Info=False;” + “User ID=sa;Initial Catalog=Northwind;” + “Data Source=MYSERVER”; SqlConnection conn = new SqlConnection(sConnString); conn.Open(); string sQueryString = “SELECT CompanyName FROM Customers”; SqlDataAdapter myDSAdapter = new SqlDataAdapter(); DataSet myDataSet = new DataSet(); myDSAdapter.SelectCommand = new SqlCommand(sQueryString, conn); myDSAdapter.Fill(myDataSet); conn.Close(); 24 5/29/2013 5/29/2013 ADO.NET Classes DataTable DataTable In-memory object representing one table Columns Rows Schema defined by Columns collection Data integrity provided through Constraint objects Public events Modifying/deleting rows Modifying columns ADO.NET Classes DataColumn DataColumn Fundamental building block of a DataTable schema (contained in Columns collection) Defines what type of data may be entered (via DataType property) Other important properties include AllowNull, Unique, and ReadOnly Can contain Constraints (a collection on DataTable) Can contain Relations (collection on DataSet) 25 5/29/2013 5/29/2013 ADO.NET Classes DataRow DataRow Represents data in a DataTable (contained in Rows collection) Conforms to schema defined by DataColumns Properties for determining row state (e.g., new, changed, deleted, etc.) All additions/modifications “committed” with AcceptChanges method of DataTable ADO.NET Classes DataRelation DataRelation Relates two DataTables via DataColumns DataType value of both DataColumns must be identical Updates can be cascaded to child DataTables Modifications that invalidate the relation are disallowed 26 5/29/2013 5/29/2013 ADO.NET Classes Creating a DataSet in Code DataSet Create DataSet Define tables DataSet dataset = new DataSet(); da...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online