新聞中心
雖然有許多人對(duì)ADO.NET數(shù)據(jù)庫(kù)的安全性表示懷疑,但在年復(fù)一年的不斷發(fā)展中,他的安全性也在不斷提高。保障ADO.NET數(shù)據(jù)庫(kù)的安全性是完全有可能的,但前提是要深入理解到底什么是ADO.NET數(shù)據(jù)庫(kù),及他是怎么運(yùn)作的。

網(wǎng)站的建設(shè)創(chuàng)新互聯(lián)專注網(wǎng)站定制,經(jīng)驗(yàn)豐富,不做模板,主營(yíng)網(wǎng)站定制開發(fā).小程序定制開發(fā),H5頁(yè)面制作!給你煥然一新的設(shè)計(jì)體驗(yàn)!已為成都石牌坊等企業(yè)提供專業(yè)服務(wù)。
使用ADO.NET數(shù)據(jù)庫(kù)的Datareader對(duì)象能從數(shù)據(jù)庫(kù)中檢索數(shù)據(jù)。檢索出來(lái)的數(shù)據(jù)形成一個(gè)只讀只進(jìn)的數(shù)據(jù)流,存儲(chǔ)在客戶端的網(wǎng)絡(luò)緩沖區(qū)內(nèi)。ADO.NET數(shù)據(jù)庫(kù)的read方法可以前進(jìn)到一下條記錄。在默認(rèn)情況下,每執(zhí)行一次read方法只會(huì)在內(nèi)存中存儲(chǔ)一條記錄系統(tǒng)的開銷非常少。#t#
創(chuàng)建datareader之前必須先創(chuàng)建sqlcommand對(duì)象,然后調(diào)用該對(duì)象的executereader方法來(lái)構(gòu)造sqldatareader對(duì)象,下面的示例程序完成的功能是訪問(wèn)ADO.NET數(shù)據(jù)庫(kù),并使用datareader從northwind數(shù)據(jù)中讀取記錄,并將查詢結(jié)果通過(guò)控制臺(tái)輸出。
- using System;
- using System.Data;
- using System.Data.SqlClient;
- namespace ReadDataFromDB{
- class Class1{
- static void Main(string[] args){
- string myconn="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind";
- 需要執(zhí)行的SQL語(yǔ)句
- string mysql="select OrderID,CustomerID from Orders where CustomerID='CHOPS'";
- 打開數(shù)據(jù)庫(kù)連接。
- SqlConnection myconnection=new SqlConnection(myconn);
- myconnection.Open();
- 創(chuàng)建SqlCommand 對(duì)象
- SqlCommand mycommand=new(mysql,myconnection);
- 通過(guò)SqlCommand的ExecuteReader()方法構(gòu)造DataReader 對(duì)象。
- SqlDataReader myreader=mycommand.ExecuteReader();
- while(myreader.read()){
- Console.WriteLine(myreader.GetInt32(0)+","+myreader.GetString(1));
- }
- myreader.Close();
- myconnection.Close();
- }
- }
- }
網(wǎng)站名稱:連接ADO.NET數(shù)據(jù)庫(kù)注意事宜及技巧
文章出自:http://m.5511xx.com/article/cocdjhi.html


咨詢
建站咨詢
