ImageVerifierCode 换一换
格式:PPT , 页数:33 ,大小:87KB ,
资源ID:376623      下载积分:2000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-376623.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Introduction to ADO, VB Database Tools and Data .ppt)为本站会员(medalangle361)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

Introduction to ADO, VB Database Tools and Data .ppt

1、Introduction to ADO.Net, VB.Net Database Tools and Data Binding,ISYS 512,Client/Server Structure,a. Presentation user interface Menus, forms, reports, etc b. Processing logic Business rules c. Database,Client,Database Server,SQL queries,Results,Database Processing,Querying database Updating database

2、: Insertion, deletion, modification,Steps to Retrieve Data,Establishes a connection to the database. Executes commands against the database. Store data results.,A Simplified View of ADO.Net Objects,Ado.Net,Data Provider,Connection,Adapter,Command,Reader,Dataset,Data Consumer,WinForm,WebForm,ADO.NET

3、Objects,Connection Object: Represent a connection to the database. Command Object: The command object allows us to execute a SQL statement or a stored procedure. DataReader: It is a read-only and forward-only pointer into a table to retrieve records. DataSet Object: A DataSet object can hold several

4、 tables and relationships between tables. DataAdapter: This the object used to pass data between the database and the dataset.,Data Providers,ODBC Provider Open Database Connectivity A driver manager Used for relational databases OLE DB Provider OLE DB interfaces provide applications with uniform ac

5、cess to data stored in diverse information sources, or data stores. Access SQL Server Provider Oracle Provider,Using ODBC,Windows XP: Control Panel /Administrative Tools/DataSource(ODBC) Three types of data source names User DSN: usable only by you and only on the machine currently using. System DSN

6、: Any one using the machine can use. File DSN: Can be copied and used by other computers with the same driver installed. Demo: Excel: Data/Import Access: File/Get External Data/Import, then select ODBC data source,VB.NET Database Tools,Database connection: Tools/Connect to database Data Source Serve

7、r Explorer Data connections: Right click data connection Add Connection Tables, Views Create new SQL Server Database Toolbox:Data tab Data/Add New Data Source,Creating SQL Server Database,From Server Explorer, right click data connection and choose: Create new SQL Server Database Server name: LocalS

8、erverNameSQLExpress Add new table: Right click Tables and choose Add New Table Add rows: Right click the table name and choose Show table data. Note: After creating the database, you may create an ODBC DSN to connect to it.,How to create ADO.Net objects?,Automatically generated when creating data bo

9、und form. Form wizard Using Data Adapter Wizard Using code: Example: dim strConn as string =“Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:sales2k.mdb“ dim objConn as new OledbConnection(strConn) objConn.open(),Data Binding,Connect a control or property to one or more data elements. Simple bindin

10、g: Use simple binding to display a field value in controls that show Data Bindings in the property window, such as text box or label. Complex binding: Use complex binding to bind more than one field to controls such as DataGrid and list box. Use the controls Data Source and Data Member to bind the d

11、ata.,Creating Data Bound Form,Creating a form with ADO.Net objects and data-bound controls to display and update information in a dataset. Demo: Add data source: Data/Add New Data Source Data/Show Data Source Click the dropdown list next to the tables name: Datagrid view Details Drag the table to fo

12、rm.,Items Added to the Form,Connection Table Adapter: click smart tag Add query Preview data Dataset: Edit in dataset designer Binding Source Add query: Add a new tool strip. Preview data Binding navigator Code view: Form load event,Generated Code,Private Sub CUSTOMERBindingNavigatorSaveItem_Click(B

13、yVal sender As System.Object, ByVal e As System.EventArgs) Handles CUSTOMERBindingNavigatorSaveItem.ClickMe.Validate()Me.CUSTOMERBindingSource.EndEdit()Me.CUSTOMERTableAdapter.Update(Me.SalesDBDataSet.CUSTOMER) End SubPrivate Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

14、 Handles MyBase.LoadTODO: This line of code loads data into the SalesDBDataSet.CUSTOMER table. You can move, or remove it, as needed.Me.CUSTOMERTableAdapter.Fill(Me.SalesDBDataSet.CUSTOMER) End Sub,Other Data Form Demos,DataGrid View Add /Modify/Delete records. Read only form: Delete AddNew, Delete,

15、 Save buttons from navigator bar.,Hierarchical Forms,Parent table/Child table Add parent table and child table to Data Source Drag the parent table and the child table to the form. Parent table uses detail view and child table uses dataGrid view Click Dataset objects smart tag to choose Edit in Data

16、set Designer With the designer, right click the parent table and choose Add/Relation Change dataGrids DataSource property to the relation.,Detail Form with Bound ListBox,Example: Customer table form with CID listbox and displays selected customer information in textboxes. Choose detail view for the

17、customer table. Click the dropdown list next to the CID field and click ListBox Drag the Customer table to the form. Bind the CID field to the BindingSource: Activate the Property window and click the listbox Set the DataSOurce property to BindingSource Set the Display Member property to CID,Creatin

18、g A Database Application Without Programming,Creating a database application to display information and update database. A main form with buttons to open data forms: DisplayInfo Enter New Modify Exit,Data Adapter Wizard,Configure Data Adapter and generating a dataset: From the Data tab of the ToolBo

19、x, Drag OledbDataAdapter to the form. Use the Data Adapter Wizard to configure the Adapter. Right Click the Adapter to preview data and create dataset. Bind the dataset to controls. In the Form Load event, use Adapters Fill method to load the dataset: OleDbDataAdapter1.Fill(DataSet11),Creating Bound

20、 DataGridView,DataGridView control: Data Source property: DataSet Data Member property A table in the dataset In the Form Load event, use Adapters Fill method to load the dataset: OleDbDataAdapter1.Fill(DataSet11) Note: A BindingSource object is created after choosing data source.,BindingSource Obje

21、ct,It is an object that keeps track of position (the current row) of a data source. Useful properties: DataSource DataMember Position property: is the index of the current row. The index is a 0-based index, the first record has a position of 0. Methods: MoveFirst, MoveLast, MoveNext, MovePrevious Ad

22、dNew AllowEdit EndEdit,Adding AddNew and Save Button,Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickCUSTOMERBindingSource.AddNew()End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.C

23、lickCUSTOMERBindingSource.EndEdit()CUSTOMERTableAdapter.Update(SalesDBDataSet1.CUSTOMER)End Sub,Adding AddNew and Save Button,AddNew button: Use BindingSource AddNew Method:,Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickCUSTOMERBindingSour

24、ce.AddNew()End Sub,Save button: Use BindingSource EndEdit method and Adapters Update method:,Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickCUSTOMERBindingSource.EndEdit() CUSTOMERTableAdapter.Update(SalesDBDataSet1.CUSTOMER)End Sub,Binding

25、Sources Position Property,If controls are bound to a BindingSource object, to move the current record we change the Position property of the BindingSource object: To move to the next record:Me.EmpBindingSource.Position += 1 Or Me.EmpBindingSource.MoveNext To move to the previous record:Me.EmpBinding

26、Source.Position -= 1 Or Me.EmpBindingSource.MovePrevious,Binding Text Box,Select Data Bindings property: Text: choose field Add navigation buttons: MoveNext: CUSTOMERBindingSource.Position += 1 MovePrevious: CUSTOMERBindingSource.Position -= 1,Other Objects Related to Data Binding,BindingContext: It

27、 is an object that manages a collection of data sources used for binding. CurrencyManager: It is an object that keeps track of position (the current row) of a data source. Two useful properties: Position property: is the index of the current row. The index is a 0-based index, the first record has a

28、position of 0. Count property: The number of rows in the data source.,MoveNext and MoveLast Example,MoveNext:Me.BindingContext(DataSet21, “customer“).Position += 1MoveLast: Me.BindingContext(DataSet21, “customer“).Position = Me.BindingContext(DataSet21, “customer“).Count -1How to MovePrevious and Mo

29、veFirst? Note: The Position property takes care of the end of file automatically. Note: Me.BindingContext(DataSet21, “customer“) returns a CurrencyManager object.,BindingNavigator Object,This object automatically adds navigation buttons to the form. Property: BindingSource property Specify a Binding

30、Source object (Must first define a BindingSource object),Binding ListBox,Example: Bind Customer Tables CID field to a listbox. Create a Adapter for Customer table , and generate the dataset. Add ListBox and set binding properties: Data Source: Customer table Display Member: Field to display in the l

31、istbox. Value Member: the actual values for items in the list box.,Display Selected Record,Bound textbox (same data source as the listbox): If the Listbox and the textbox are bound to the same BindingSource object, the textbox will automatically displays the record of the selected listbox item. Unbo

32、und textbox To display the ValueMember Textbox1.text = ListBox1.SelectedValue To display other fields: Textbox1.text = ListBox1.SelectedItem(“Cname”) Can we use TextBox1.text=ListBox1.SelectedItem?No!,ListBox SelectedItem Property,How to display the selected record in unbound textbox? After binding

33、to a data source, this property return a DataRowView object. What is DataRowView? Object Browser: System.Data DataRowView: Item property is the default property To retrieve a column from a DataRowView object (use 0-based index to identity a column): ListBox1.SelectedItem.Item(1) Or: ListBox1.SelectedItem(1) Or: ListBox1.SelectedItem(“Cname”),Using Object Browser,View/Object Browser DataSet object model: System.Data DataSet Relations Tables Rows Columns Use Object Browser to study objects properties, methods.,

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1