偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

歸納總結(jié)ADO.NET對象

開發(fā) 后端
這里介紹了ADO.NET對象:Connection、Command、DataReader、DataAdapter、DataSet、DataTable,詳細(xì)請看正文介紹。

我們知道做程序就得訪問數(shù)據(jù)庫,在網(wǎng)上收集了大量的資料,現(xiàn)在和大家分享一下吧。ADO.NET是Microsoft數(shù)據(jù)庫訪問的一種新技術(shù),它支持連接式訪問和斷開式訪問兩種方案。ADO.NET中定義了一套接口IDbConnection、IDbCommand、IDbDataAdapter和IDDataReader,并且還有顯示這些接口的抽象類:DbConnection、DbCommand、DbDataAdapter以及DataReader;不同的數(shù)據(jù)庫廠商實(shí)現(xiàn)這些接口的抽象類各不相同。
◆ADO.NET對象Connection:Connection對象有兩個屬性:ConnectionString 和 State;以及兩個重要方法:Open和close。
◆ADO.NET對象Command:Command對象有一個屬性:CommandType(sql語句或者存儲過程);三個重要方法:ExecuteNonQuery(增、刪、改影響的行數(shù))、ExecuteReader(返回DataReader對象類型)ExecuteScalar(返回結(jié)果集的***行***列值)
◆ADO.NET對象DataReader:DataReader對象不能直接實(shí)例化,必須通過Command對象中的一個方法來創(chuàng)建;DataReader有很多屬性,Read(是否還有下一條數(shù)據(jù)),讀取數(shù)據(jù)的屬性(三中方式)
◆ADO.NET對象DataAdapter:作用是充當(dāng)適配器;其中有一個重要方法Fill,這個方法可以在不打開數(shù)據(jù)庫連接的情況進(jìn)行數(shù)據(jù)操作
◆ADO.NET對象DataSet:相當(dāng)于內(nèi)存中的一個數(shù)據(jù)庫,使用DataAdapter對象填充DataSet或者DataTable
◆ADO.NET對象DataTable(DataColumn對象和DataRow對象):它有兩個屬性Columns和Rows;

 參數(shù)化SQL語句:

Sql2005查詢方法:

  1. //實(shí)例化Connection對象   
  2. SqlConnection connection = new SqlConnection("Data Source=(local);Initial Catalog=AspNetStudy;Persist Security Info=True;User ID=sa;Password=sa");   
  3. //實(shí)例化Command對象   
  4. SqlCommand command = new SqlCommand("select * from UserInfo where sex=@sex and age>@age", connection);   
  5. //***種添加查詢參數(shù)的例子   
  6. command.Parameters.AddWithValue("@sex", true);   
  7. //第二種添加查詢參數(shù)的例子   
  8. SqlParameter parameter = new SqlParameter("@age", SqlDbType.Int);//注意UserInfo表里age字段是int類型的   
  9. parameter.Value = 30;   
  10. command.Parameters.Add(parameter);//添加參數(shù)   
  11. //實(shí)例化DataAdapter   
  12. SqlDataAdapter adapter = new SqlDataAdapter(command);   
  13. DataTable data = new DataTable();  

占位符:

分頁查詢:首先計算出總行數(shù),其次算出多少頁

首先:

  1. int count = int.Parse(command.ExecuteScalar().ToString()); 

其次:

  1. page=(m%n)==0?(m/n):(m/n+1);    

n為每頁顯示的行數(shù)

***:

  1. select top 5 * from UserInfo where UserId not in  
  2. (select top (n-1)*5 UserID from UserInfo order by UserID asc)  
  3. order by UserID asc 

【編輯推薦】

  1. Linq匿名類型簡單概述
  2. Linq隨機(jī)讀取數(shù)據(jù)淺析
  3. Linq Lambda表達(dá)式全面分析
  4. Linq擴(kuò)展方法簡單分析
  5. 初探Linq局部變量類型
責(zé)任編輯:田樹 來源: 博客
相關(guān)推薦

2009-11-04 10:35:42

ADO.NET Con

2009-11-13 15:25:51

ADO.NET的對象

2009-11-04 14:17:34

ADO.NET 2.0

2009-11-12 15:12:57

ADO.NET實(shí)體框架

2009-11-11 14:27:32

ADO.NET函數(shù)

2009-11-04 12:45:33

ADO.NET Dat

2009-12-21 15:58:19

ADO.NET集合

2010-05-24 09:49:47

ADO.NET

2009-11-04 16:55:16

ADO.NET Dat

2009-11-03 15:24:14

ADO.NET對象模型

2009-11-04 10:23:05

ADO.NET Con

2009-12-21 17:35:24

ADO.NET對象

2009-11-13 14:38:45

ADO.NET Dat

2009-06-18 09:56:44

ADO.NET對象模型

2009-12-21 17:02:19

ADO.NET Sql

2009-11-12 16:04:42

ADO.NET對象查詢

2009-12-28 13:47:31

ADO.NET對象

2009-12-18 14:27:24

ADO.NET對象

2009-11-04 11:30:35

ADO.NET Dat

2009-11-12 15:38:18

ADO.NET數(shù)據(jù)平臺
點(diǎn)贊
收藏

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