Transcript WinForms – Basic Controls
Data Classes- DataView DataGridView Control
1
Objectives Data Class DataAdapter DataReader DataSet DataTable DataView DataGridView Control Summary 2
DataAdapter Properties 3
Demo SqlDataAdapter is the best way to load data from server to DataSet 4
SqlDataAdapter : properties - Events DeleteComman d InsertComman d SelectComman d UpdateComman d
RowUpdate RowUpdating
SqlDataAdapter dataAdapt SqlCommand cmd = new SqlDataAdapter(); = new SqlCommand(“Select * from authors” , con); dataAdapt .SelectCommand = cmd ; DataSet ds = new DataSet(); dataAdapt.
Fill(ds); 5
OleDbDataAdapter Used to connect to multiple databses such as : SQLServer , Access , Oracle Exists in the namespace : System.Data.OleDb
Have the same properties and events as SqlDataAdapter 6
FieldCount HasRow IsClosed Item RecordsAffe cted SqlDataReader class • Used to read data from SQL Server in a sequential manner and have some properties : • Forward-only - Read Only • Get it by call the ExecuteReader() method of SqlCommand object • Read data by Read() method 7
SqlDataReader : Method 8
DataSet • A representation of a database in cached-memory • Included datatable and relation and contrains
Ex
: DataSet ds = new DataSet() 9
Method – Kind of DataSet
TypeDataSet :
-Have a schema : .xsd
UntypeDataSet :
-Create by a code : DataSet A = new DataSet()
Navigate Record :
Using Binding source class and use some methods of this class as : - MoveFirst - MoveLast - MoveNext - MovePrevious 10
DataSet and XML
DataSet can fetch data from a XML file
• ReadXML(string path) : read XML file to DataSet • WriteXML(string path) : save the content DataSet to a XML file 11
DataTable class • Represent a table in DataSet • Have a constraint objects that ensure data integrity Properties 12
Method 13
DataTable: Event 14
DataTableCollection • The DataTableCollection class is a collection of the tables in DataSet • Collection of the DataTable class 15
DataRelation • Maintains referential integrity by enforcing foreign-key constraint • Unique constraint • Cascade update and delete operation • Use to relate two DataColumn Object that exits in two DataTable 16
DataColumn class • Used for creating a schema for a particular column • You can add a column to a DataColumnCollection 17
DataRow class Represent a row in a DataTable 18
DataTableReader 19
DataTableReader
DataTableReader
dtr = dataTable.
CreateDataReader()
20
Demo 21
Summary Data Class DataAdapter DataReader DataSet DataTable 22
DataView class Used to sort , filter , search , modify and navigate through the record Constructor of this class is a dataTable 23
Properties 24
25
DataViewManager 26
DataGrid control • Display data in a tabular format • Populated by the table present in dataSet ( binding) • Insert , delete , update DataSet 27
DataGridView control
28
DataGridView control 29
Example 30
DataGridView & DataGrid control 31
Summary 32