日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
ASP.NET數(shù)據(jù)庫(kù):SQLServer四類典型代碼

ASP.NET數(shù)據(jù)庫(kù)操作代碼有很多分類,今天,我們就來(lái)看一下SQL Server方面的四類典型代碼。

ASP.NET數(shù)據(jù)庫(kù)操作代碼之DataReader

作用:DataReader閱讀類,執(zhí)行數(shù)據(jù)的“只向前”的讀取。

只讀、只進(jìn)的數(shù)據(jù)流。因?yàn)槊看卧趦?nèi)存中的數(shù)據(jù)只有一行,所以使用DataReader可提高應(yīng)用程序的性能并減少系統(tǒng)開(kāi)銷。它還提供了未緩沖的數(shù)據(jù)流,該數(shù)據(jù)流使過(guò)程邏輯可以有效地按順序處理從數(shù)據(jù)源中返回的結(jié)果。由于數(shù)據(jù)不在內(nèi)存中緩存,所以在檢索大量數(shù)據(jù)時(shí),DataReader是一種合適的選擇。

 
 
 
  1. string strConn="uid=賬號(hào);pwd=密碼;database=數(shù)據(jù)庫(kù);server=服務(wù)器";  
  2.  
  3.   SqlConnection ConnSql=new SqlConnection (strConn);  
  4.  
  5.   ConnSql.Open ();//打開(kāi)數(shù)據(jù)庫(kù)  
  6.  
  7.   string strSQL="SELECT * FROM 表名1";SqlCommand cmd = new SqlCommand(strSQL,ConnSql);SqlDataReader dr=cmd.ExecuteReader();Read();  
  8.  
  9.   dr.Close();Close();//關(guān)閉數(shù)據(jù)庫(kù) 

ASP.NET數(shù)據(jù)庫(kù)操作代碼之DataSet

作用:DataSet,DataAdapter讀取數(shù)據(jù)。

 
 
 
  1. string strConn="uid=賬號(hào);pwd=密碼;database=數(shù)據(jù)庫(kù);server=服務(wù)器";  
  2.  
  3.   SqlConnection ConnSql=new SqlConnection (strConn);  
  4.  
  5.   ConnSql.Open ();string strSQL="SELECT * FROM 表名1 ";  
  6.  
  7.   SqlDataAdapter da=new SqlDataAdapter(strSQL,ConnSql); DataSet ds=new DataSet();Fill(ds,"自定義虛擬表名");Close ();//關(guān)閉數(shù)據(jù)庫(kù) 

ASP.NET數(shù)據(jù)庫(kù)操作代碼之ExecuteNonQuery

作用:利用ExecuteNonQuery,執(zhí)行數(shù)據(jù)的插入、更新、刪除。

問(wèn):什么是ExecuteNonQuery?

答:在ADO.NET中,ExecuteNonQuery方法用于執(zhí)行不需要返回結(jié)果的命令,如插入、刪除和更新等操作。

 
 
 
  1. string strConn="uid=賬號(hào);pwd=密碼;database=數(shù)據(jù)庫(kù);server=服務(wù)器";  
  2.  
  3.   SqlConnection ConnSql=new SqlConnection (strConn);  
  4.  
  5.   ConnSql.Open ();string strSQL="INSERT INTO 表名1、UPDATE 表名1 SET、DELETE FROM 表名1";SqlCommand cmd=new SqlCommand (strSQL,ConnSql);ExecuteNonQuery();Close ();//關(guān)閉數(shù)據(jù)庫(kù) 

ASP.NET數(shù)據(jù)庫(kù)操作代碼之ExecuteScalar

作用:利用ExecuteScalar統(tǒng)計(jì)數(shù)據(jù)。

問(wèn):什么是ExecuteScalar?

答:ExecuteScalar方法可以返回單個(gè)值,如求和、總行數(shù)等SQL語(yǔ)句的聚合函數(shù)。

 
 
 
  1. string strConn="uid=賬號(hào);pwd=密碼;database=數(shù)據(jù)庫(kù);server=服務(wù)器";  
  2.  
  3.   SqlConnection ConnSql=new SqlConnection (strConn);  
  4.  
  5.   ConnSql.Open ();//打開(kāi)數(shù)據(jù)庫(kù)  
  6.  
  7.   string strSQL="SELECT COUNT(*) FROM 表名1";SqlCommand cmd = new SqlCommand(strSQL,ConnSql);int intNum=(int)cmd.ExecuteScalar();Close();//關(guān)閉數(shù)據(jù)庫(kù) 

以上就是asp.net與Sql Server數(shù)據(jù)庫(kù)操作使用代碼的介紹,希望對(duì)大家有所幫助。


本文標(biāo)題:ASP.NET數(shù)據(jù)庫(kù):SQLServer四類典型代碼
文章鏈接:http://www.dlmjj.cn/article/dpecgop.html