自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

ASP.NET數(shù)據(jù)庫操作代碼小結(jié):SQL Server篇

開發(fā) 后端
本文總結(jié)了ASP.NET數(shù)據(jù)庫操作代碼,用于SQL Server。

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

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

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

string strConn="uid=賬號(hào);pwd=密碼;database=數(shù)據(jù)庫;server=服務(wù)器";

SqlConnection ConnSql=new SqlConnection (strConn);

ConnSql.Open ();//打開數(shù)據(jù)庫

string strSQL="SELECT * FROM 表名1";SqlCommand cmd = new SqlCommand(strSQL,ConnSql);SqlDataReader dr=cmd.ExecuteReader();Read();

dr.Close();Close();//關(guān)閉數(shù)據(jù)庫

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

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

string strConn="uid=賬號(hào);pwd=密碼;database=數(shù)據(jù)庫;server=服務(wù)器";

SqlConnection ConnSql=new SqlConnection (strConn);

ConnSql.Open ();string strSQL="SELECT * FROM 表名1 ";

SqlDataAdapter da=new SqlDataAdapter(strSQL,ConnSql); DataSet ds=new DataSet();Fill(ds,"自定義虛擬表名");Close ();//關(guān)閉數(shù)據(jù)庫

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

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

問:什么是ExecuteNonQuery?

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

string strConn="uid=賬號(hào);pwd=密碼;database=數(shù)據(jù)庫;server=服務(wù)器";

SqlConnection ConnSql=new SqlConnection (strConn);

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ù)庫

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

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

問:什么是ExecuteScalar?

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

string strConn="uid=賬號(hào);pwd=密碼;database=數(shù)據(jù)庫;server=服務(wù)器";

SqlConnection ConnSql=new SqlConnection (strConn);

ConnSql.Open ();//打開數(shù)據(jù)庫

string strSQL="SELECT COUNT(*) FROM 表名1";SqlCommand cmd = new SqlCommand(strSQL,ConnSql);int intNum=(int)cmd.ExecuteScalar();Close();//關(guān)閉數(shù)據(jù)庫

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

【編輯推薦】

  1. ASP.NET中Bind和Eval的區(qū)別:兩種綁定
  2. 簡單的ASP.NET常用代碼(2)
  3. 簡單的ASP.NET常用代碼(1)
  4. ASP.NET技巧:非托管COM組件的使用
  5. ASP.NET中拼接字符串的另一實(shí)現(xiàn):Response.Write 

責(zé)任編輯:book05 來源: hi.baidu
相關(guān)推薦

2009-07-28 11:00:24

Excel導(dǎo)入SQL

2009-09-03 19:30:02

ASP.NET數(shù)據(jù)庫SQL Server

2009-08-05 09:38:28

SQL Server數(shù)

2009-08-12 11:04:38

ASP.NET和SQL

2009-07-24 12:14:17

asp.net技巧

2009-07-28 11:23:04

Excel導(dǎo)入SQL

2009-02-23 15:20:03

SQL Server數(shù)據(jù)庫ASP.NET

2009-07-31 09:57:47

ASP.NET數(shù)據(jù)庫緩

2009-07-28 17:36:21

ASP.NET數(shù)據(jù)庫連

2009-03-09 17:46:16

ASP.NETSQLOracle

2009-07-29 09:12:31

ASP.NET數(shù)據(jù)庫連

2009-08-11 12:52:05

ASP.NET數(shù)據(jù)庫程

2009-08-05 15:40:49

ASP.NET連接數(shù)據(jù)

2009-07-31 16:09:23

ASP.NET數(shù)據(jù)庫圖

2009-07-31 16:45:23

ASP.NET數(shù)據(jù)庫操

2009-07-27 17:58:10

ASP.NET數(shù)據(jù)庫編

2010-05-25 08:49:33

連接MySQL

2009-09-13 22:35:12

ASP.NET數(shù)據(jù)庫

2009-07-28 14:16:31

ASP.NET與MyS

2011-08-25 16:50:20

SQL ServerAccessASP
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)