1. Trang chủ
  2. » Giáo án - Bài giảng

Chapter 7 Create, Add, Delete, and Edit Data in a Disconnected Environment

50 383 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 50
Dung lượng 277,11 KB

Nội dung

Chapter 7 Create, Add, Delete, and Edit Data in a Disconnected Environment Objectives in chapter  Create a DataSet graphically.  Create a DataSet programmatically.  Add a DataTable to a DataSet.  Add a relationship between tables within a DataSet.  Navigate a relationship between tables.  Merge DataSet contents.  Copy DataSet contents.  Create a typed DataSet.  Create DataTables.  Manage data within a DataTable.  Create and use DataViews.  Represent data in a DataSet by using XML. (NO)  Use the OleDbDataAdapter object to access an ADO Recordset or Record.  Generate DataAdapter commands automatically by using the Command-Builder object. Before we go…  Con.connectionString=“….”;  /// con.Open(); -> do not need  cmd.Connectiion=con;  cmd.CommandType="Select ", conSinhVien)  cmd.CommandText=“Select * from …”;  DataAdapter da=new DataAdapter();  Da.SelectCommand=cmd;  Dataset Ds=new Dataset();  Da.Fill(Ds);  DataGrid1.DataSource=ds.tables[0]; Chapter content  Lesson 1:Creating DataSet Objects  Lesson 2: Creating DataTable Objects.  Lesson 3: Creating DataAdapter Objects  Lesson 4: Working with Data in DataTable Objects  Lesson 6: Creating and Using DataView Objects Lesson 1: Creating DataSet Objects  DataSet Objects  Creating DataSet Objects Programmatically Lesson 1: Creating DataSet Objects  DataSet Objects  temporarily store the data  Like array, in memory Dataset structure Objective: Using in-memory database  DataSet Structure  DataTable Structure DataColumn DataRow  Build manual dataset  DataView  Example Why DataSet?  Perform database modifications  always disconnected  To transfer data between tiers have .NET framework (Linux, Unix, Windows…)  To send between computers across network by HTTP protocol in XML format  To manipulate the data without an open connection  To relate data from multiple sources  To bind data to a Windows form  Power data structure  Event an application without database, we can using dataset … instead of arraylist, array… Populating DataSets  Manual  From existing databae, using DataAdapter  Read from XML data files  Build from XSD files  But before filling dataset… … we need to know dataset structure DataSet Components  DataTable  DataColumn  DataRow  Constraint  DataRelation  DataView [...]... DataTable DataRow DataColumn Populating DataSet-Manual Construct your own DataSet (schema) 1 1 2 3 4 Create Dataset Add DataTable(s) Add DataColumn(s) to DataTable Define datatable schema Fill Data into DataTable(s) in DataSet 2 1 2 Add DataRow to DataTable Processing data in dataset … Dim ds As New DataSet , r As DataRow With ds.Tables.Add("SV") Columns.Add("id") Columns.Add("Name") End With With ds.Tables("SV")... What Is a DataAdapter Between Dataset/Datatable and Database Connect to Command and Connection Fill and Update Dataset/DataTable Disconect to Dataset/DataTable Lesson 3: Creating DataAdapter Objects How to Create DataAdapter Objects Dim SqlDataAdapter1 as New SqlDataAdapter("SELECT * FROM Shippers", NorthwindConnection) Or Dim cmd as new Command … commandtype, commandext SqlDataAdapter1.SelectCommand=cmd... Row Relation DataTable DataSet DataTable Represents one table in DataSet Are accessed using the DataSet's Tables property Collection of DataTables Using index : ds.tables(0) Using name: ds.tables(“authors”) Each DataTable has: A Columns property DataColumn DataRow DataTable DataColumn DataRow (Add,remove,removeat,Item) A Rows property (Add,remove,removeat,Item) Dim DT1 As New DataTable("TableNam Access... DataTable Objects Create a DataTable Add a DataTable to a DataSet Dim NorthwindDataset As New DataSet("NorthwindData") ' Create a new DataTable Dim CustomersTable As New DataTable("Customers") ' Add the Datatable to the Dataset's Tables collection NorthwindDataset.Tables.Add(CustomersTable) Lesson 2: Creating DataTable Objects Create Expression Columns in DataTable Objects Dim TotalPriceColumn As New DataColumn("TotalPrice",... authors.PrimaryKey = new DataColumn[] {Cid}; DataRow Class A DataRow object provides access to one row of data in a DataTable DataSet A DataTable's DataRow objects contain all the data in the DataTable Create DataTable DataColumn DataRow Table.NewRow method Can access DataRow values by providing: Column name Column number DataColumn object Core Pro./methods Item(index) : get cell value IsNull Delete DataTable... 3: Creating DataAdapter Objects DataAdapter Commands SelectCommand InserCommand UpdateCommand DeleteCommand Build 4 commands when using Dataadapter??? Lesson 3: Creating DataAdapter Objects DataAdapter Commands: manual build command Dim SqlDataAdapter1 As New SqlDataAdapter("SELECT * FROM Shippers", NorthwindConnection) Dim InsertCommand As New SqlCommand("Valid SQL Insert statement", NorthwindConnection)... "aa" r("name") = "bb" Rows.Add(r) End With DataView An custom view of a DataTable Sorting, filtering, searching, editing, and navigating the data from a DataSet Using same data memory from Datatable Each DataTable have DefaultView DataTable row1 row2 row3 SV1 SV2 SV3 Nguyen thi A Nguyen thi C Nguyen thi B row2 row3 row1 row1 row3 row2 DataView1 DataView2 Dataview Changes DataView affect DataTable automatically... Configuration Wizard Questions? Lesson 1: Creating DataSet Objects Exercise 3: Configuring Untyped DataSet Objects Questions? Lesson 2: Creating DataTable Objects Create a DataTable Add a DataTable to a DataSet Define the schema of a DataTable Add columns to a table Create expression columns Create AutoIncrementing columns Define a primary key for a table Add constraints to a table Lesson 2: Creating DataTable... Access to data- cell Table.Rows(index).Item(index) DataTable Core Pro./Methods TableName property A PrimaryKey property array of datacolumn Select(filter): datarow() End of sql NewRow DefaultView Example: Create table and dataset Ds=new DataSet(); ds.DataSetName = "BookAuthors"; Tauthors =new DataTable("Author"); Ds.Tables.add (Authors); DataTable Accessing example myDataTable.Rows(5) returns a DataRow object... Similar to column in datatable DataSet DataTable DataColumn DataRow Doesn’t have Value property Core Pro / methods ColumnName DataType DataTable Ex Gettype(integer) AllowDBNull AutoIncrement DefaultValue Unique ReadOnly DataRow DataColumn Example DataColumn Cid = authors.Columns.Add("ID",gettype(integer)); Cid.AutoIncrement = true; DataColumn Cname = authors.Columns.Add("Name", gettype(String)); authors.PrimaryKey . Chapter 7 Create, Add, Delete, and Edit Data in a Disconnected Environment Objectives in chapter  Create a DataSet graphically.  Create a. DataAdapter();  Da.SelectCommand=cmd;  Dataset Ds=new Dataset();  Da.Fill(Ds);  DataGrid1.DataSource=ds.tables[0]; Chapter content  Lesson 1:Creating DataSet Objects  Lesson 2: Creating DataTable Objects.  Lesson

Ngày đăng: 13/05/2014, 12:19

TỪ KHÓA LIÊN QUAN