Chapter 10Accessing Database Files.ppt
《Chapter 10Accessing Database Files.ppt》由会员分享,可在线阅读,更多相关《Chapter 10Accessing Database Files.ppt(46页珍藏版)》请在麦多课文档分享上搜索。
1、Chapter 10 Accessing Database Files,Programming In Visual Basic.NET, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 2,Visual Basic and Databases,VB projects can display and update the data from database files VB.NET uses ADO.NET for database access ADO.NET is the next generation of
2、 database technology, based on Microsofts previous version ActiveX Data Objects (ADO), 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 3,ADO.NET,Data is stored and transferred in Extensible Markup Language (XML) Allows access to database data in many formats Two types of Connections
3、 SQLClient for SQL Server OLEDB for all other database formats, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 4,Relational Database Terminology,Database includes Tables = collection of related data Queries = SQL designed to select data from tables Table Record = row of related dat
4、a for one instance Field = column of specific data element Keys Primary = uniquely identifies a record Foreign = links record to related record in related table Relationships, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 5,Using ADO.NET and VB,Can display data from a database on
5、Windows Form Web Form Add controls to form and bind data to them Normal Controls like label, textbox Special controls designed just for data like DataGrid, DataList, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 6,Steps for Data Access, 2001 by The McGraw-Hill Companies, Inc. All
6、rights reserved.,10- 7,Connection,Used to establish link form specific file or database to program Types SqlConnection Microsoft SQL Server databases only OleDBConnection All other databases, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 8,Setting Up a Connection,Can be accomplish
7、ed from Toolbox Server Explorer window Within Data Adapter Configuration Wizard using New Connection button No matter which method above is used to begin the connection, the Data Link Properties dialog appears for you to complete the task, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.
8、,10- 9,Creating a Connection from Server Explorer,Click Connect to Database buttonOR Right-click Data Connections, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 10,Data Link Properties Dialog,Used to define Connections OLE DB Provider Actual DB Filename Logon UserName and Password
9、 (optional) Used to Test Connection, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 11,Connections in Server Explorer,Shows all created Connections Same Connection can be use for multiple projects Expand Connection node to view tables and fields, 2001 by The McGraw-Hill Companies,
10、Inc. All rights reserved.,10- 12,Data Adapter,Does all the work of passing data back and for the between a data source and a program Does not have to be a database Can be text file, object, or even an array Types, must match Connection type OleDbDataAdapter SqlDataAdapter Use db prefix (e.g. dbRnR),
11、 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 13,Setting Up a Data Adapter from Server Explorer,Drag Table name to formOR CTRL-click Field names and drag to form, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 14,Data Adapter Configuration Wizard,Walks you throu
12、gh the steps for selecting fields in a database Only used if you create/add a Data Adapter from the Toolbox Can be used to modify existing Data Adapters also, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 15,Dataset,Temporary set of data stored in memoryIn ADO.NET datasets are dis
13、connected; the copy of data kept in memory does not keep an active connection to the data sourceDataset may contain multiple tables and relationships, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 16,Defining a Dataset,Drag Dataset control from the toolbox to form Select Data menu
14、, Generate Dataset Right-click on Data Adapter and select Generate Dataset In all cases, you see the Generate Dataset dialog box, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 17,Defining a Dataset (cont.),Name dataset with ds prefix in Generate Dataset dialog (e.g. dsBooks), 2001
15、 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 18,Data Passing from Data Source to Dataset to User Interface, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 19,XML Data,Industry-standard format for storing and transferring data Specifications at http:/www.w3.org/XML,
16、World Wide Web Consortium (W3C) The needed XML for accessing databases will be automatically generated for you in Visual Basic, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 20,XML,Data stored in XML is all text XML Data File Contains actual data XML Schema File Contains descripti
17、ons for Fields Data Types Constraints, such as required fields .xsd file in Solution Explorer, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 21,Fill Method,Method of the Data Adapter executed at run time to fill the dataset Usually coded in Form_Load (or Page_Load for Web Projects
18、) General Form DataAdapterName.Fill (DataSetName) ExampledbRnR. Fill (dsBooks1), 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 22,Creating Bound Controls: Data Grid,In Windows Form Set properties of the controls Use Fill method Example: Grid Control New control in VB.NET Displays
19、database records as a table Steps Set up/add Connection, DataAdapter, DataSet Add DataGrid control from toolbox (dbg prefix), 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 23,Creating Bound DataGrid,Steps continued Set properties of DataGrid to bind to data DataSource to DataSet n
20、ame DataMember to Table nameAdd code to populate control with data Windows Form, Form_Load = DataAdapterName.Fill (DataSetName), 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 24,Creating Simple Bound Controls,Labels and text boxes Same steps: Set up/add Connection, DataAdapter, Da
21、taSet Add text boxes or label control from toolbox Set properties to bind to data Data Binding properties menu Text option to be specifiedAdd code to populate control with data Windows Form, Form_Load = DataAdapterName.Fill (DataSetName), 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,
22、10- 25,Navigating Through DataSets,Refer to the Position and Count properties of the Windows Forms BindingContext, Move to next record Me.BindingContext(dsBooks1, “Books“).Position + = 1 Move to previous record Me.BindingContext(dsBooks1, “Books“).Position - = 1 Move to the first record Me.BindingCo
23、ntext(dsBooks1, “Books“).Position = 0 Move to the last record With Me.BindingContext(DsCustomer1, “Customer“).Position = .Count - 1 End With, 2001 by The McGraw-Hill Companies, Inc. All rights reserved.,10- 26,Retrieving Record Count,Specify DataSet Table Name Rows Collection Count Property Example
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- CHAPTER10ACCESSINGDATABASEFILESPPT
