1 / 18

第 10 章 数据库及应用

第 10 章 数据库及应用. UIBE SIT. 1. ADO.NET 概要. .NET Framework 数据提供程序 SQL Server.net 数据提供程序 PAGE 283 OLE DB.NET 数据提供程序 SQLOLEDB MSDAORA Microsoft Jet OLEDB 4.0 .net 数据提供程序模型的核心对象 : Conection Command Datareader dataAdapter. DataSet 数据集对象 (Page 283) 是内存驻留表现形式 无论数据是什么 , 都会提供一致的关系编程模型

chinue
Download Presentation

第 10 章 数据库及应用

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第10章 数据库及应用 UIBE SIT

  2. 1. ADO.NET概要 • .NET Framework数据提供程序 • SQL Server.net数据提供程序 • PAGE 283 • OLE DB.NET数据提供程序 • SQLOLEDB • MSDAORA • Microsoft Jet OLEDB 4.0 • .net数据提供程序模型的核心对象: • Conection • Command • Datareader • dataAdapter

  3. DataSet数据集对象(Page 283) • 是内存驻留表现形式 • 无论数据是什么,都会提供一致的关系编程模型 • 可用于多个不同的数据源 • 表示整个数据集,包括 • 相关表 • 约束 • 表间关系

  4. Steps Of Data Application Development In Ado.Net • 根据数据库,选择数据提供程序(MYSQL? ACCESS? ORACLE?) • 建立与数据源的连接-CONNECTION • 执行对数据源的操作命令-SQL命令 • 使用数据集对获得的数据进行操作-Datareader, DataSet等 • 向用户显示数据-数据控件

  5. 2. SQL语言(page 284) • 数据查询 • 记录处理

  6. 3.ADO.net对象及其编程 • Connection 对象与使用-连接 • Command对象及使用-操作 • Commandtype • Commandtext

  7. DataReader对象及使用 • 从数据源检索只读\只向前数据集-大量数据检索 • 属性:FieldCount/RecordAffected • 方法:Read/NextResult/Close/Get • DataAdapter对象及使用 • 属性:Page 290 • 方法:Fill/Update

  8. DataSet对象和使用 • 组成 • Datatable/datarelation/dataColumn/dataRow • 填充 • Fill • 访问 • Rows/Columns

  9. 如何连接SQL SERVER数据库 • 7.0以上版本 • Page 286 • 7.0以下版本或OLE DB 数据源 • Page 286

  10. 举例,教材287(step 1,2) Imports System.Data Imports System.Data.OleDb Public Class Form1 Private Sub btnConn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConn.Click Dim cString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data_ Source=d:\Northwind.mdb" Dim MyCon As New OleDbConnection(cString) myCon.Open()

  11. Dim sqlStr as String=“Select *.* From 订单 ” • Dim myCom as New OleDbCommand() • myCom.Connection=myCon • myCom.commandType=Commandtype.text • myCom.commandText=sqlStr

  12. dataAdapter Dim myDataAdapter As New OleDbDataAdapter myDataAdapter.SelectCommand = myCom Dim myDs As New DataSet myDataAdapter.Fill(myDs, "订单") Label1.Text = ""

  13. dataset For i = 0 To myDs.Tables("订单").Rows.Count - 1 strRow = myDs.Tables("订单").Rows(i).ItemArray(0) & " “ strRow = strRow + myDs.Tables("订单").Rows(i)("客户ID") & " " strRow = strRow + myDs.Tables_ ("订单").Rows(i).ItemArray(2).ToString() Label1.Text = Label1.Text + strRow + Chr(10) + Chr(13) Next i

  14. 4.数据库控件的使用 • DATAgrid • Datagridviwer • textBox

  15. 用Navigator绑定数据表 • 设置 Navigator = Me.BindingContext(MyDs, “订单") ‘ • 使用 If (Navigator.Position = 0) Then '如果已是第一条记录 Navigator.Position = Navigator.Count - 1 '把记录指针移到最后一条记录 Else Navigator.Position -= 1 '记录指针减,即移到上一条记录 End If DispValue() '显示当前记录的值

  16. 理解 • Connetion:使用数据库的方法 • Command:使用SQL命令 • Adapter:数据集/数据表 • Dataset:字段 • Navigator = Me.BindingContext(MyDs, “订单")

  17. The SQL Command • Selects rows and columns from a table. • Columns can be limited by specifying only the wanted ones. • Rows can be limited through a Where clause. Select * From Friends Select ID, FirstName, LastName From Friends Select ID, FirstName, LastName From Friends Where LastName = “Smith”

  18. Sumup • 连接 • 命令 • 适配器 • 数据集 • 参见本章上机练习

More Related