sqladapter 生成 dataset 或 datatable
1. 创建一个 sqlcommand 对象以调用该存储过程,并将其与一个 sqlconnection 对象(显示)或连接字符串(不显示)相关联。
2. 创建一个新的 sqldataadapter 对象并将其与 sqlcommand 对象相关联。
3. 创建一个 datatable(也可以创建一个 dataset)对象。使用构造函数参数来命名 datatable。
4. 调用 sqldataadapter 对象的 fill 方法,用检索到的行填充 dataset 或 datatable。
如何使用 sqldatareader 来检索多个行
以下代码片段阐明了可检索多个行的 sqldatareader 方法
using system.io;
2 using system.data;
3 using system.data.sqlclient;
4
5 public sqldatareader retrieverowswithdatareader()
6 {
7 sqlconnection conn = new sqlconnection(
8 "server=(local);integrated security=sspi;database=northwind");
9 sqlcommand cmd = new sqlcommand("datretrieveproducts", conn );
10 cmd.commandtype = commandtype.storedprocedure;
11 try
12 {
13 conn.open();
14 // generate the reader. commandbehavior.closeconnection causes the
15 // the connection to be closed when the reader object is closed
16 return( cmd.executereader( commandbehavior.closeconnection ) );
17 }
18 catch
19 {
20 conn.close();
21 throw;
22 }
23 }
24
25 // display the product list using the console
26 private void displayproducts()
27 {
28 sqldatareader reader = retrieverowswithdatareader();
29 try
30 {
31 while (reader.read())
32 {
33 console.writeline("{0} {1} {2}",
34 reader.getint32(0).tostring(),
35 reader.getstring(1) );
36 }
37 }
38 finally
39 {
40 reader.close(); // also closes the connection due to the
41 // commandbehavior enum used when generating the reader
42 }
43 }
樱花校园模拟器4399中文版
樱花校园模拟器4399中文版,十分奇趣好玩的3d校园冒险模拟
我的暑假秘密回忆繁星新春版
我的暑假秘密回忆繁星新春版是一款少女模拟养成类休闲游戏。这款
樱花校园模拟器国际版
樱花校园模拟器国际版,一个超级自由超级好玩的自由恋爱模拟的游
饥荒海难九游版
饥荒海难九游版,带你去真实的海岛上感受一下什么才是真正的孤岛
盖瑞模组体验版最新版
盖瑞模组体验版是玩法非常丰富多元化的沙盒建造游戏,玩家可以在