版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、本科畢業(yè)設(shè)計(jì)(英文文獻(xiàn)翻譯)數(shù)據(jù)庫(kù)用戶接口有能力的數(shù)據(jù)庫(kù)應(yīng)用設(shè)計(jì)者和創(chuàng)建者總是被當(dāng)作公司或者商業(yè)的巨大資產(chǎn),并且應(yīng)當(dāng)這樣。在用戶需要通過(guò)局域網(wǎng)、廣域網(wǎng)或者因特網(wǎng)交互數(shù)據(jù)時(shí),這些人能夠解決許多關(guān)鍵性的問(wèn)題。如果你已經(jīng)構(gòu)建起數(shù)據(jù)庫(kù)系統(tǒng),剩下的就只是如何構(gòu)建接口來(lái)讓用戶與這些系統(tǒng)進(jìn)行交互。還有一些其它方面你需要了解,例如:設(shè)計(jì)一個(gè)適合三層構(gòu)架的系統(tǒng),這些將在以后討論。當(dāng)今的銀行、商店以及許多企業(yè)的日常工作都是基于一定數(shù)據(jù)庫(kù)系統(tǒng)來(lái)完成。如果沒(méi)有數(shù)據(jù)庫(kù)系統(tǒng),它們將不能有效地運(yùn)轉(zhuǎn)。這就是開(kāi)發(fā)者發(fā)揮他們才能和不可或缺作用的地方。為了能夠綁定一個(gè)用戶接口,如果可以的話,也可以綁定其他相關(guān)商業(yè)部分,數(shù)據(jù)源是很有
2、價(jià)值的一個(gè)資本。想想最近一次你使用應(yīng)用程序,也許是一本雇員電話本、顧客數(shù)據(jù)庫(kù)、清單程序,或者是財(cái)政程序,想想它們?nèi)绾问占瘮?shù)據(jù)并且用一種友好的方式展現(xiàn)給你。一旦能夠建立這些形式的應(yīng)用,就擁有了能夠很容易地進(jìn)行信息處理的潛能,能夠給整個(gè)公司帶來(lái)利益,這就是為什么程序員成為如此珍貴資本的原因。 當(dāng)今的許多公司都雇傭一個(gè)個(gè)人或者群體專門進(jìn)行已存在的數(shù)據(jù)庫(kù)的管理即就是數(shù)據(jù)庫(kù)管理員(DBAs)并且擁有一組單獨(dú)的開(kāi)發(fā)人員,他們的任務(wù)是進(jìn)行自己應(yīng)用程序的創(chuàng)建。但是,作為數(shù)據(jù)庫(kù)開(kāi)發(fā)者的你常常兼有這兩方面的工作,所以你需要深入了解這兩個(gè)任務(wù)。數(shù)據(jù)庫(kù)管理員的職責(zé)包括: 數(shù)據(jù)庫(kù)構(gòu)架知識(shí)和如何高效地運(yùn)用和存儲(chǔ)信息。 使
3、數(shù)據(jù)庫(kù)能夠正常運(yùn)行的能力。 洞察公司在成長(zhǎng)和擴(kuò)大中的需求變化的能力現(xiàn)在的數(shù)據(jù)庫(kù)框架能否處理十倍甚至百倍數(shù)量級(jí)的信息而保持高效率? 當(dāng)進(jìn)行用戶接口設(shè)計(jì)時(shí)有一套邏輯方法,屏幕按一種用戶能夠理解的方式進(jìn)行組織例如相關(guān)組進(jìn)行控制,比如用戶和地址字段。 與用戶緊密地工作來(lái)設(shè)計(jì)這些系統(tǒng)的能力。 在進(jìn)行客戶服務(wù)器應(yīng)用程序時(shí)這些將會(huì)有幫助。當(dāng)我們開(kāi)發(fā)數(shù)據(jù)庫(kù)時(shí)我們需要考慮諸如:效率、靈活性、處理多用戶、數(shù)據(jù)鎖定、數(shù)據(jù)增長(zhǎng)、完善性和性能等。開(kāi)發(fā)可戶端應(yīng)用程序的人員需要像考慮程序性能和效率一樣考慮用戶接口界面。擁有一個(gè)聰明的想法:知道用戶將會(huì)如何與數(shù)據(jù)庫(kù)系統(tǒng)進(jìn)行交互將會(huì)幫你決定如何設(shè)計(jì)它。用戶在運(yùn)行任務(wù)時(shí)總是按一定
4、的順序運(yùn)行特定的程序,某些任務(wù)比其他的要用的多。例如,如果你在設(shè)計(jì)一套儲(chǔ)備清單程序,你也許想讓你的系統(tǒng)在開(kāi)啟時(shí)顯示能讓用戶更改清單的界面,而不是添加新產(chǎn)品行。 在這章中,我們將來(lái)看看為一個(gè)SQL 數(shù)據(jù)源建立一個(gè)基本用戶接口的重要基本。我們也將看看當(dāng)你建立一些更老練的數(shù)據(jù)庫(kù)應(yīng)用時(shí)所應(yīng)該應(yīng)用的一些好的實(shí)踐。下面就是我們?yōu)榇四康亩采w的主題: 一個(gè)用來(lái)訪問(wèn)數(shù)據(jù)庫(kù)的簡(jiǎn)單用戶接口 怎樣填充一個(gè)DataGrid 運(yùn)用向?qū)?幕后產(chǎn)生的代碼 一般用戶接口設(shè)計(jì)的好的實(shí)踐1 用戶接口 既然你已經(jīng)學(xué)會(huì)了怎樣運(yùn)用合適的SQL 語(yǔ)句來(lái)設(shè)計(jì)數(shù)據(jù)庫(kù)并且更新數(shù)據(jù)庫(kù)里的信息。我們不能等待我們的用戶去開(kāi)發(fā)一套數(shù)據(jù)庫(kù)管理工具并且
5、像這樣來(lái)操縱數(shù)據(jù),因此,我們下一步就是要?jiǎng)?chuàng)造某種途徑來(lái)讓用戶去訪問(wèn)信息。這就是用戶接口的作用提供一種用戶和數(shù)據(jù)庫(kù)的通信手段。 通過(guò)用戶接口,用戶可以與數(shù)據(jù)交互并且操縱它來(lái)完成一定的任務(wù),比如:查看、添加、更新或者刪除細(xì)節(jié)。用戶接口和數(shù)據(jù)庫(kù)親密地進(jìn)行工作,并且正確結(jié)合,用戶能夠不用任何特殊的技術(shù)知識(shí)而處理大量的信息。 需要某中思考過(guò)程或者方法來(lái)為接口提出一種好的設(shè)計(jì):我們想建立一個(gè)一致并且和諧的界面以便這個(gè)接口對(duì)將要用它的用戶來(lái)說(shuō)是容易接近的。我們應(yīng)該知道現(xiàn)存的數(shù)據(jù)邏輯,當(dāng)讓用戶進(jìn)行像添加和刪除信息時(shí)保證這些動(dòng)作是正確的,防止用戶不經(jīng)意的操縱數(shù)據(jù)造成一些對(duì)企業(yè)來(lái)說(shuō)不可恢復(fù)的損失。安全性和數(shù)據(jù)完整
6、性很重要,因?yàn)樗鼈兲峁┝藱C(jī)制來(lái)保證用戶不能調(diào)整他們自己財(cái)產(chǎn)的平衡,修改他們自己的獎(jiǎng)金,或者查看甚至修改其他用戶的信息。我們需要一種方法來(lái)隱藏幕后的制衡。這些中的許多都可通過(guò)好的框架設(shè)計(jì)來(lái)完成,來(lái)造成一種能夠訪問(wèn)、使之有效并且保護(hù)這個(gè)信息,或者通過(guò)框架后的代碼或者讓這些框架去調(diào)用另一個(gè)對(duì)象。還有一種可能性是一個(gè)惡意的用戶可能會(huì)完全饒過(guò)這些模型,并且嘗試著去直接訪問(wèn)數(shù)據(jù)庫(kù),因此嚴(yán)密的安全是非常重要的。為了達(dá)到這個(gè)目的,我們的模型應(yīng)該制作成一個(gè)帶有保密用戶ID 和密碼的數(shù)據(jù)庫(kù),我們能通過(guò)存儲(chǔ)過(guò)程隱藏我們的制衡信息也就是存儲(chǔ)在數(shù)據(jù)庫(kù)服務(wù)器端的程序。這些存儲(chǔ)過(guò)程能履行一些基于已通過(guò)參數(shù)的標(biāo)準(zhǔn),并且只有當(dāng)
7、正確的安全信息通過(guò)時(shí)才返回信息。所有的這些都是通過(guò)商業(yè)規(guī)則來(lái)完成的,這些規(guī)則提出這樣的要求:數(shù)據(jù)在特殊的與我們的生意有關(guān)時(shí)如何維護(hù)。 既然我們已對(duì)與用戶接口相關(guān)的問(wèn)題了解了一部分,我們可以繼續(xù)來(lái)看看我們?cè)鯓釉赩isual Basic .NET 里創(chuàng)建一個(gè)接口。這個(gè)應(yīng)用程序的基本要素是窗體框架,它們可以被看作是一個(gè)等待被畫(huà)入的白布。我們可以在這個(gè)框架中放置控件來(lái)為我們的接口設(shè)計(jì)一種有邏輯性的界面,并且為用戶提供一種自然而簡(jiǎn)單的途徑來(lái)讓用戶與數(shù)據(jù)庫(kù)交互。2 ADO.NET 概述 在我們開(kāi)始創(chuàng)建我們的應(yīng)用程序之前我們需要來(lái)學(xué)習(xí)一下我們的應(yīng)用程序?qū)⒁玫降囊恍〢DO.NET 基本要素和向?qū)?。我們將在?/p>
8、一章中更詳細(xì)地描述ADO.NET ,因此,現(xiàn)在我們將僅學(xué)習(xí)一下基本來(lái)使我們通過(guò)這個(gè)簡(jiǎn)單的數(shù)據(jù)庫(kù)工程。 ADO.NET 提供給我們一種收集數(shù)據(jù)和信息并且通過(guò)一個(gè)用戶接口展示數(shù)據(jù)的方法。通過(guò)運(yùn)用一些要素,我們能夠聯(lián)系上各種數(shù)據(jù)源然后創(chuàng)建一個(gè)訪問(wèn)數(shù)據(jù)庫(kù)的用戶接口。 我們需要四個(gè)部分來(lái)創(chuàng)建我們的ADO.NET工程。1. 一個(gè)數(shù)據(jù)源真正的數(shù)據(jù)被存儲(chǔ)的地方,我們的數(shù)據(jù)庫(kù)2. 一個(gè)Connection對(duì)象來(lái)將我們聯(lián)系到我們的數(shù)據(jù)庫(kù)3. 一個(gè)DataAdapter對(duì)象來(lái)創(chuàng)建一種讀取和向數(shù)據(jù)庫(kù)中寫(xiě)入的機(jī)制4. 一個(gè)數(shù)據(jù)集對(duì)象它將包含我們將要用到的表 首先,我們需要一個(gè)與數(shù)據(jù)源的連接,被一個(gè)Connection
9、對(duì)象所提供。該對(duì)象要求一定的信息來(lái)與數(shù)據(jù)庫(kù)連接。Connection對(duì)象被DataAdapter對(duì)象所調(diào)用,DataAdapter對(duì)象處理命令來(lái)對(duì)數(shù)據(jù)源進(jìn)行選擇、更新、插入和刪除數(shù)據(jù)。最后,我們有一個(gè)DataSet來(lái)裝入我們的表并且它通過(guò)DataAdapter填充自己并且對(duì)數(shù)據(jù)源中的數(shù)據(jù)進(jìn)行更新。一、數(shù)據(jù)源數(shù)據(jù)源是描述提供給我們數(shù)據(jù)的任意信息集合的規(guī)定。它可能采取數(shù)據(jù)庫(kù), XML 文件的形式, 報(bào)表, 甚至一個(gè)文本或二進(jìn)制文件。它只采取一兩個(gè)代碼行使我們改變我們連接的數(shù)據(jù)源。Windows環(huán)境提供我們公共類用于我們的程序用相同的代碼與不同的數(shù)據(jù)源通信。二、數(shù)據(jù)連接我們連接數(shù)據(jù)庫(kù)的第一件事是數(shù)據(jù)
10、連接對(duì)象。它引用二種形式- SqlConnection 或OleDbConnection 對(duì)象。就像我們操作SQL 服務(wù)器引擎, 我們將使用SqlConnection 對(duì)象。當(dāng)我們使用SQLConnection對(duì)象創(chuàng)建連接時(shí),我們需要使用下面的連接參數(shù): 數(shù)據(jù)源-數(shù)據(jù)源被放置位置的服務(wù)器名字。數(shù)據(jù)源可能被放在任何地方, 可能是在網(wǎng)絡(luò)或互聯(lián)網(wǎng)上。通常, 您使用你的本地網(wǎng)絡(luò),你便需要存放數(shù)據(jù)源的專門計(jì)算機(jī)名字。我們也可用localhost 或(local) 來(lái)代替我們運(yùn)行程序的計(jì)算機(jī)。這項(xiàng)術(shù)語(yǔ),當(dāng)它作為當(dāng)前,本地計(jì)算機(jī)時(shí),由許多Windows 應(yīng)用使用。 用戶標(biāo)識(shí)和密碼-連接數(shù)據(jù)源所需要的認(rèn)證,用
11、戶標(biāo)識(shí)和密碼是由數(shù)據(jù)庫(kù)管理員建立的,他防止其他用戶在未經(jīng)允許的情況下查看或更改數(shù)據(jù)庫(kù)。 初始化日志這是我們想要與之工作的數(shù)據(jù)庫(kù)。 為了創(chuàng)建一個(gè)新的連接,我們聲明一個(gè)新的SqlConnection 并且運(yùn)用以下所示的這些參數(shù)設(shè)置ConnectionString 屬性:Dim myConnection As New SqlClient.SqlConnection()myConnection.ConnectionString = Data Source=localhost; & _Initial Catalog=NorthwindSQL;UserId=sa;Password=sa;或者,我們可以將連
12、接串作為一個(gè)參數(shù)傳遞給SqlConnection ,如下所示:Dim myConnection As New SqlClient.SqlConnection(Data Source=localhost; & _Initial Catalog=NorthwindSQL;UserId=sa;Password=sa; 創(chuàng)建一個(gè)新的OleDbConnection 對(duì)象是簡(jiǎn)單的,除非我們同時(shí)需要一個(gè)提供者參數(shù)來(lái)描述我們正在連接的數(shù)據(jù)源的類型。因此,為什么我們不需要那個(gè)與SqlConnection 對(duì)象相關(guān)的參數(shù)?你已經(jīng)掌握它了因?yàn)樘峁┱哳愋蛯?huì)一直是SQL 并且,實(shí)際上如果你真的試著將提供者參數(shù)設(shè)置為S
13、qlConnection 對(duì)象,你將會(huì)出錯(cuò)。 現(xiàn)在我們可以來(lái)看看這個(gè)需要一個(gè)數(shù)據(jù)連接對(duì)象來(lái)建立以便能運(yùn)轉(zhuǎn)的要素,即就是DataAdapter 。三、DataAdapter DataAdapter 是位于數(shù)據(jù)源和數(shù)據(jù)集之間的一種機(jī)制。我們擁有兩種類型的DataAdapters :SqlDataAdapter ,專門為SQL Server 數(shù)據(jù)庫(kù)所使用;OleDbDataAdapter ,被所有的數(shù)據(jù)源所使用并且通過(guò)另外一個(gè)被稱為OLE DB的層。因此,通過(guò)防止這個(gè)額外層的需要,SqlDataAdapter 提供更快數(shù)據(jù)的訪問(wèn)。OleDbDataAdapter 可以被用來(lái)訪問(wèn)SQL Server
14、,但是,因?yàn)樗ㄟ^(guò)OLE DB 層,如果你打算就用SQL Server 而不是任何其他的,為了達(dá)到最好性能你將被建議保持和SqlDataAdapter 一致。這適合這章中的簡(jiǎn)單數(shù)據(jù)庫(kù)應(yīng)用程序,因此我們嚴(yán)格與SqlDataAdapter 一致地工作。DataAdapter 允許進(jìn)行選擇、更新、刪除或者向數(shù)據(jù)源中插入數(shù)據(jù)。這些方法通過(guò)使用SelectCommand, UpdateCommand, InsertCommand, 和DeleteCommand屬性來(lái)設(shè)置為了特定操作所需要的數(shù)據(jù)庫(kù)命令字符串來(lái)實(shí)現(xiàn)。這些屬性中的每一個(gè)都是一個(gè)命令對(duì)象的例子,它們的工作即就是執(zhí)行一個(gè)SQL 語(yǔ)句或者存儲(chǔ)過(guò)程并
15、且返回一個(gè)結(jié)果集。對(duì)一個(gè)SQL 數(shù)據(jù)庫(kù)來(lái)說(shuō),命令對(duì)象將保持著為規(guī)定操作實(shí)際所需的選擇、更新、插入和刪除語(yǔ)句,比如:SELECT * FROM Products 或者DELETE FROM Orders WHERE CustomerID=ABC。命令對(duì)象還存儲(chǔ)著連接信息因此它能夠連接上數(shù)據(jù)庫(kù)來(lái)執(zhí)行它所包含的SQL 語(yǔ)句。在此指出,在我們簡(jiǎn)化了的例子中,我們將僅用SelectCommand 工作因?yàn)槲覀冎恍枰獜奈覀兊臄?shù)據(jù)庫(kù)中選擇信息來(lái)進(jìn)行查詢。 因?yàn)槲覀兒鸵粋€(gè)SQL 數(shù)據(jù)庫(kù)打交道,我們將利用SqlCommand 對(duì)象(和OleDBCommand 對(duì)象相對(duì)應(yīng))。當(dāng)我們利用DataAdapter 向?qū)?/p>
16、時(shí),對(duì)每個(gè)表來(lái)說(shuō)你都將有一個(gè)對(duì)應(yīng)的DataAdapter 。 當(dāng)我們運(yùn)用向?qū)r(shí),為了使選中的表能夠擁有所有的對(duì)其更新和恢復(fù)信息,DataAdapters 被特別配置。為了對(duì)另外一個(gè)表重用它,我們主要需要重建組成DataAdapter 的對(duì)象,這意味著所有的命令對(duì)象都要被重建。簡(jiǎn)單的解決方案是每個(gè)表分配一個(gè)DataAdapter ,這樣幫助你讓你的代碼保持整潔并且容易維護(hù)。當(dāng)你建立一個(gè)DataAdapter 時(shí),如果需要你可以明確指定多于一個(gè)表。比如,我們可以創(chuàng)建一個(gè)聯(lián)系顧客表和訂購(gòu)表的DataAdapter 來(lái)使我們能夠只用單個(gè)DataAdapter 就能從兩個(gè)表中查看信息,而不需要任何的代碼
17、來(lái)連接它們。但是,當(dāng)遇到更新信息時(shí),這種將多個(gè)表連接成一個(gè)表視圖的方法就運(yùn)行的不是很好,因?yàn)镈ataAdapter 向?qū)Р荒軌蜻m當(dāng)將表連接起來(lái)來(lái)串聯(lián)更新和刪除,強(qiáng)化了一個(gè)表一個(gè)DataAdapter 的情況。四、數(shù)據(jù)集 最后,一個(gè)數(shù)據(jù)集是表的一個(gè)容器或者集合;它能夠包含一個(gè)或者多個(gè)表并且在主存中被維護(hù)。表間關(guān)系也被保存在這里。它所保持的表將諸如顧客詳細(xì)情況或產(chǎn)品信息的信息以記錄或行的格式包含在一起。一個(gè)表可能包含幾千個(gè)這樣的行。 一個(gè)有用的說(shuō)明是將一個(gè)數(shù)據(jù)集想象為保持一個(gè)書(shū)籍出版者的細(xì)節(jié)。一個(gè)有技術(shù)的出版者可能以幾種類別發(fā)布書(shū)刊,比如像.NET,JAVA,ASP和C+ 。在每個(gè)類型中都是單獨(dú)的
18、書(shū)刊因此一個(gè).NET 類型應(yīng)該擁有像專業(yè)版VB.NET ,基本VB.NET ,專業(yè)C#,和引領(lǐng).NET 。一張表應(yīng)能代表這些種類中的一種,并且一個(gè)類型內(nèi)的每本書(shū)應(yīng)該被適當(dāng)?shù)谋碇械囊恍兴?。每一行保持著每本?shū)的細(xì)節(jié)例如:標(biāo)題、價(jià)格、ISBN 編號(hào)、出版日期和頁(yè)數(shù)等。 對(duì)于你能向數(shù)據(jù)集中存儲(chǔ)的信息類型并沒(méi)有限制。既然我們已經(jīng)了解了一個(gè)數(shù)據(jù)集的內(nèi)部細(xì)節(jié),就讓我們來(lái)看看怎樣在一個(gè)應(yīng)用程序中應(yīng)用一個(gè)數(shù)據(jù)集。 對(duì)我們的程序來(lái)說(shuō),我們將需要建立一個(gè)SqlDataAdapter 對(duì)象來(lái)從向?qū)?shù)據(jù)庫(kù)中通過(guò)一個(gè)SqlConnection 對(duì)象選擇顧客記錄。這個(gè)連接將被僅僅維持完成SQL 選擇操作的時(shí)間。我們將通
19、過(guò)運(yùn)用SqlDataAdapter 對(duì)象把我們的顧客表中數(shù)據(jù)填充到我們的數(shù)據(jù)集中。連接,或者數(shù)據(jù)綁定,對(duì)諸如DataGrid 控件的可視化控件將會(huì)在窗口模型中展示數(shù)據(jù)集中的內(nèi)容。 現(xiàn)在我們可以在我們簡(jiǎn)單的數(shù)據(jù)庫(kù)應(yīng)用程序中執(zhí)行這些控件。下面是以下任務(wù)的一個(gè)概述: 創(chuàng)建一個(gè)窗口應(yīng)用程序 與一個(gè)數(shù)據(jù)源建立連接 向我們的框架中添加一個(gè)DataAdapter 從DataAdapter 產(chǎn)生一個(gè)數(shù)據(jù)集 向我們的框架中添加一個(gè)DataGrid 控件 在我們的DataGrid 中顯示顧客表的內(nèi)容 我們以創(chuàng)建一個(gè)新的Visual Studio .NET 應(yīng)用程序然后再向工程中添加一個(gè)SqlDataAdapter
20、 作為開(kāi)端。我們?nèi)匀恍枰獮镈ataAdapter 創(chuàng)建一個(gè)與NorthwindSQL 數(shù)據(jù)庫(kù)聯(lián)系的連接。從SqlDataAdapter 我們將創(chuàng)建一個(gè)新的數(shù)據(jù)集。一旦我們有了數(shù)據(jù)集,我們將向我們的框架中添加一個(gè)DataGrid 并且將數(shù)據(jù)集和它綁定。最后,我們將添加一個(gè)按扭來(lái)將顧客記錄填充到數(shù)據(jù)集中,并且在DataGrid 中展示出來(lái)。 Visual Studio .NET 的配置向?qū)槲覀兲峁┝艘粋€(gè)簡(jiǎn)單的方法來(lái)做這些。現(xiàn)在我們離創(chuàng)建我們的數(shù)據(jù)庫(kù)應(yīng)用程序只有一點(diǎn)點(diǎn)距離了!3 數(shù)據(jù)訪問(wèn)簡(jiǎn)史 數(shù)據(jù)訪問(wèn)方法自從Microsoft Access 1.0 和Visual Basic 3.0 時(shí)就存在了。
21、數(shù)據(jù)庫(kù)存取工作利用Visual Basic 變得很容易,好象他們?nèi)匀辉跒楹?jiǎn)單桌面應(yīng)用程序做工作。 Visual Basic 中的第一個(gè)數(shù)據(jù)模型被稱為數(shù)據(jù)訪問(wèn)對(duì)象(ADO),在Visual Basic 3.0 中介紹。它能夠與Microsoft Access 和其他類型的數(shù)據(jù)庫(kù)交互,盡管它對(duì)于你的臺(tái)式計(jì)算機(jī)來(lái)說(shuō)很好用。它很容易被用因?yàn)樗峁┝撕?jiǎn)單的數(shù)據(jù)訪問(wèn)方法和工具,從Visual Basic IDE 環(huán)境而來(lái),比如說(shuō)數(shù)據(jù)綁定控件。這些工具和大量的諸如書(shū)籍和技術(shù)報(bào)告之類的資源,意味著你能夠緊接著很快使一個(gè)數(shù)據(jù)庫(kù)應(yīng)用程序運(yùn)轉(zhuǎn)起來(lái)。Visual Basic 環(huán)境和一個(gè)數(shù)據(jù)管理者連接在一起,這個(gè)管理者
22、允許創(chuàng)建和管理數(shù)據(jù)庫(kù)存取,并且,當(dāng)你將你的應(yīng)用程序分散時(shí),創(chuàng)建進(jìn)程允許對(duì)任何需要的數(shù)據(jù)訪問(wèn)圖書(shū)館進(jìn)行簡(jiǎn)單選擇。它仍然允許你寫(xiě)入并運(yùn)用一套代碼來(lái)訪問(wèn)不同的數(shù)據(jù)源,因?yàn)椋挥幸患赂淖?,即你所想連接到的數(shù)據(jù)源的類型。這些數(shù)據(jù)源主要是非關(guān)系數(shù)據(jù)庫(kù)。 非關(guān)系數(shù)據(jù)庫(kù)通常是作為連續(xù)二進(jìn)制流存儲(chǔ)的平文件。ISAM(索引順序存取方法)數(shù)據(jù)庫(kù)運(yùn)用這種類型并且提供一種控制計(jì)算機(jī)怎樣訪問(wèn)存儲(chǔ)在硬盤上記錄和文件的途徑。數(shù)據(jù)被連續(xù)地存儲(chǔ),直接訪問(wèn)一個(gè)具體的記錄需要運(yùn)用索引。這些文件的結(jié)構(gòu)十分復(fù)雜。很多讀取這種類型數(shù)據(jù)的引擎,在訪問(wèn)記錄時(shí)非常的迅速而有效,因?yàn)椴恍枰ㄟ^(guò)多余的層,并且他們可以直接訪問(wèn)數(shù)據(jù)。這樣隱藏著一個(gè)不
23、好的方面,即它們?nèi)狈θ魏伟踩珯C(jī)制來(lái)保護(hù)數(shù)據(jù),任何人都可以進(jìn)入查看或者編輯數(shù)據(jù)庫(kù)中信息,并且也沒(méi)有歷史事務(wù)被維持來(lái)記錄是誰(shuí)、什么或者什么時(shí)候記錄被改變了。這種系統(tǒng)不是為多服務(wù)框架而設(shè)計(jì)的,在多服務(wù)框架里進(jìn)程可以被分開(kāi)來(lái)使顧客計(jì)算機(jī)做很多的數(shù)據(jù)進(jìn)程工作。它們對(duì)多用戶環(huán)境的適應(yīng)力很差,并且也不提供固有的機(jī)制來(lái)阻止用戶同時(shí)進(jìn)行的相互有影響的改變操作。作者:里克特.J來(lái)源:深入理解.net6本科生畢業(yè)設(shè)計(jì)(英文文獻(xiàn))The User Interface for the DatabaseCapable database application designers and builders are inva
24、riably considered a great asset to a company or business, and rightly so. Such people are able to solve a number of problems in situations where users need to interact with data be it accessed over a LAN, WAN, or the Internet. Once you have acquired the knowledge to build database systems, there rea
25、lly only remains the know-how to build an interface that allows users to talk to these systems. There are other aspects of development you need to be aware of, for instance designing a system geared towards a three-tier architecture, and these will be discussed later.Banks, stores, and most business
26、es today all depend on some type of database system for their day-to-day operations and, without it, they would no longer be able to run efficiently. This is where you as the developer have a crucial role to play. To be able to tie a user interface, and other related business components if desired,
27、to a data source is a valuable asset. Think of the last application you used around your office, perhaps an employee phonebook, customer database, inventory program, or finance program, and how they all gathered data and presented it to you in a friendly manner. Being able to build these types of ap
28、plication, that have the potential to make dealing with information so much easier, can bring great benefits throughout a company, and so it is that such programmers become highly valued assets. Many companies nowadays employ a person or group solely for the management of existing databases the data
29、base administrators (DBAs) and have a separate team of developers whose job it is to build the applications themselves. Often, however, you as the database developer will be playing both roles, and so you will need a basic understanding of both tasks. The DBAs responsibilities include: Knowledge of
30、the structure of the database and how to use and store information in an efficient manner The ability to normalize a database, as talked about in the Chapter 1 Insight into the changing demands of the company as it grows and expands will the database in its present form be able to handle ten or even
31、 a hundred times the amount of information and remain efficient? A logical methodology when it comes to the user interface design, so screens are organized in a way that makes sense to the user for instance grouping related controls together, such as customer and address fields. The ability to work
32、closely with the user to design these systems.This will all help when it comes to developing client-server applications. When we develop databases we need to consider such things as efficiency, flexibility, handling multiple users, data locking, data growth, integrity, and performance. The person de
33、veloping the client-side of the application needs to worry about how the user interface will look as well as the performance and efficiency of the application. Having a clear idea of how users will interact with your database system will help in determining how it should be built. Users will often p
34、erform certain procedures in a certain order when undertaking tasks, and some tasks will be much more common than others. For instance, if you are designing a stock inventory application, you might want your system to start up with the screen that allows users to make changes to the inventory, rathe
35、r than, say, the screen for adding new product lines.In this chapter, we look at the fundamentals of building a basic user interface to a SQL data source. Well also look at some good practices that you should apply when building more sophisticated database applications. Here are the topics we will c
36、over to this end: A simple user interface for accessing a database How to populate a DataGrid Using Wizards The code generated behind the scenes Good practices for general user interface design1 The User InterfaceSo youve learned how to design a database and how to update information in it using sui
37、table SQL statements. We cant expect our users to open up an administrative database tool and manipulate the data directly like this, so our next step is to create some way for users to access information. This is the role of the user interface to provide a means of communication between the user an
38、d the database.Through the user interface, users may interact with data and manipulate it in order to accomplish certain tasks such as to view, add, update, or delete details. The user interface and database go hand in hand, and with the right combination, users are able to handle massive amounts of
39、 information without any particular technical knowledge.Some type of thought process or methodology is required to come up with a good design for the interface: we want to create a consistent and appropriate look so that the interface is readily accessible to those who are to use it. We should be aw
40、are of existing business logic when allowing the user to do things like add or delete information to ensure its done correctly and to prevent users from inadvertently manipulating data in a way that could potentially result in irrecoverable losses to the business. Security and data integrity are imp
41、ortant, for they provide the mechanisms to ensure users are not able to adjust their own bank balances, modify prices themselves, or view or even change other peoples information. We need a way to hide the checks and balances behind the scenes. Most of this can be accomplished through good design of
42、 forms, to build in the capability to call upon, validate, and protect this information; either through the code behind the forms or by having the forms calls another object. There is also the possibility that a malicious user could bypass these forms entirely, and attempt to directly access the dat
43、abase, so watertight security is vital. To achieve this, our forms can be made to access the database with a secret user ID and password, and we can hide our checks and balances through stored procedures that is, procedures stored on the database server. These stored procedures can perform some vali
44、dation based on what parameters are passed, and only return information when correct security information has been passed. All this is accomplished through business rules, which dictate how data will be maintained in the particular scenarios relevant to our business.Now that we know a little about t
45、he issues involved with the user interface, we can move on to look at how we can build an interface in Visual Basic .NET. The fundamental component of this type of application is the Windows Form, which can be viewed as an empty canvas waiting to be painted on. We can place controls on such a form t
46、o create a logical look and feel for our interface, and provide a natural and intuitive way for the user to communicate with our database.2 A Brief Introduction to ADO.NETBefore we can begin creating our application we need to learn about some basic components of ADO.NET and wizards that our applica
47、tion is to use. We will go into greater detail on ADO.NET in the next chapter so, for now, well learn just enough to get us through this simple database project.ADO.NET provides us with a way of gathering data and information and presenting it through a user interface. By using some components, were
48、 able to connect to various data sources and can then build a user interface that accesses a database.We need four pieces to build our ADO.NET project:1. A data source where the actual data is stored, our database.2. A Connection object for connecting us to our database.3. A DataAdapter object to pr
49、ovide a mechanism for reading and writing data to the database.4. A DataSet object this will contain the table(s) that we will use.Firstly, we need a connection to the data source, provided by a Connection object. The Connection object requires certain information for it to connect to the data sourc
50、e. The Connection object is called by the DataAdapter object, which handles commands to select, update, insert, and delete data in the data source. Finally we have a DataSet that contains our tables and which uses the DataAdapter to populate itself and to update information in the data source.一、The
51、Data SourceA data source is the term used to describe any collection of information that can provide data to us. It can take the form of a database, an XML document, a Microsoft Excel spreadsheet, or even a flat text or binary file. It only takes one or two lines of code for us to change the kind of
52、 data source that we connect to. The Windows environment provides us a shared set of classes for use in our programs to communicate with these different sources using similar code.二、The Data ConnectionThe first thing we need to connect to a database is the data Connection object. This comes in two v
53、ersions either a SqlConnection or OleDbConnection object. As we are working with the SQL Server Desktop Engine, we will use the SqlConnection object. When we create a connection using a SqlConnection object, we need to feed it the following connection parameters: Data Source the name of the server w
54、here your data source is located. The data source can be anywhere, be it on your network or somewhere over the Internet. Usually, you will be working on your local network and so you need to specify the name of the computer that holds the data source here. Alternatively, we can give the name localho
55、st or (local) to signify that we want to use the computer that is actually running the application. This terminology is used by many Windows applications when it is necessary to identify the current, local computer. User ID and Password the authentication details required to communicate with the dat
56、a source. The ID and password is set up by the database administrator and helps prevent people from viewing or modifying the database without permission. Initial Catalog this is the name of the database we want to work with in this case, NorthwindSQL.To create a new connection, we declare a new SqlC
57、onnection and set the ConnectionString property using these parameters as shown here:Dim myConnection As New SqlClient.SqlConnection()myConnection.ConnectionString = Data Source=localhost; & _Initial Catalog=NorthwindSQL;UserId=sa;Password=sa;Alternatively, we can pass the connection string as a par
58、ameter to the SqlConnection as follows:Dim myConnection As New SqlClient.SqlConnection(Data Source=localhost; & _Initial Catalog=NorthwindSQL;UserId=sa;Password=sa;Creating a new OleDbConnection object is similar, except that we also need a Provider parameter to describe the type of data source that we are connecting to. So why dont we need that parameter with the SqlConnection object? Youve got it because the provider type will always be SQL and, in fact, if you do t
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度潯購(gòu)F000353632食品級(jí)冰柜采購(gòu)協(xié)議3篇
- 2025年度個(gè)人房產(chǎn)買賣居間代理服務(wù)協(xié)議3篇
- 二零二五年度環(huán)保型打印耗材研發(fā)與銷售合同可打印協(xié)議書(shū)下載3篇
- 醫(yī)療技術(shù)產(chǎn)品的研發(fā)與市場(chǎng)應(yīng)用
- 二零二五年度瓷磚行業(yè)環(huán)保公益活動(dòng)贊助合同3篇
- 未來(lái)辦公環(huán)境綠色辦公創(chuàng)業(yè)項(xiàng)目策劃
- 二零二五年度編織袋行業(yè)政策研究與解讀合同3篇
- 2025版顯示屏技術(shù)改造與升級(jí)合同3篇
- 湖北2025年湖北武漢理工大學(xué)專職輔導(dǎo)員招聘筆試歷年參考題庫(kù)附帶答案詳解
- 2025年度鋼構(gòu)工程鋼結(jié)構(gòu)焊接與檢驗(yàn)合同協(xié)議
- 云南省普通高中學(xué)生綜合素質(zhì)評(píng)價(jià)-基本素質(zhì)評(píng)價(jià)表
- 2024年消防產(chǎn)品項(xiàng)目營(yíng)銷策劃方案
- 旅游公司發(fā)展規(guī)劃
- 聞道課件播放器
- 03軸流式壓氣機(jī)b特性
- 五星級(jí)酒店收入測(cè)算f
- 大數(shù)據(jù)與人工智能ppt
- 人教版八年級(jí)下冊(cè)第一單元英語(yǔ)Unit1 單元設(shè)計(jì)
- GB/T 9109.5-2017石油和液體石油產(chǎn)品動(dòng)態(tài)計(jì)量第5部分:油量計(jì)算
- 邀請(qǐng)函模板完整
- 2023年江蘇省南京市中考化學(xué)試卷2
評(píng)論
0/150
提交評(píng)論