国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ado.net數據操作全接觸二(query,Parameters)

2024-07-10 13:02:50
字體:
來源:轉載
供稿:網友

5.1使用sqldatareader進行數據庫查詢
1: <%@ import namespace="system.data" %>
2: <%@ import namespace="system.data.sqlclient" %>
3:
4: <%
5: dim myconnection as sqlconnection
6: dim mycommand as sqlcommand
7: dim mydatareader as sqldatareader
8:
9: myconnection = new sqlconnection( "server=localhost;uid=sa;database=pubs" )
10: myconnection.open()
11: mycommand = new sqlcommand( "select * from authors", myconnection )
12: mydatareader = mycommand.executereader()
13: while mydatareader.read()
14:  response.write( mydatareader.item( "au_lname" ) )
15: end while
16: mydatareader.close()
17: myconnection.close()
18: %>
19:
5.2在c#中使用sqldatareader 進行數據庫查詢
 1: <%@ page language="c#" %>
2: <%@ import namespace="system.data" %>
3: <%@ import namespace="system.data.sqlclient" %>
4:
5: <%
6: sqldatareader mydatareader;
7: sqlconnection myconnection = new http://aspfree.com/chapters/sams/graphics/ccc.gifsqlconnection( "server=localhost;uid=sa;database=pubs" );
8: myconnection.open();
9: sqlcommand mycommand = new sqlcommand( "select * from http://aspfree.com/chapters/sams/graphics/ccc.gifauthors", myconnection );
10: mydatareader = mycommand.executereader();
11: while ( mydatareader.read() )
12: {
13:  response.write( mydatareader[ "au_lname" ].tostring() );
14: }
15: mydatareader.close();
16: myconnection.close();
17: %>
18:
5.3使用oledbdatareader進行數據庫查詢
1: <%@ import namespace="system.data" %>
2: <%@ import namespace="system.data.oledb" %>
3:
4: <%
5: dim myconnection as oledbconnection
6: dim mycommand as oledbcommand
7: dim mydatareader as oledbdatareader
8:
9: myconnection = new oledbconnection( "provider=microsoft.jet.oledb.4.0;data http://aspfree.com/chapters/sams/graphics/ccc.gifsource=c:/authors.mdb" )
10: myconnection.open()
11: mycommand = new oledbcommand( "select * from authors", myconnection )
12: mydatareader = mycommand.executereader()
13: while mydatareader.read
14:  response.write( mydatareader.item( "author" ) )
15: end while
16: mydatareader.close()
17: myconnection.close
18: %>
19:
5.5使用sql parameters
1: <%@ import namespace="system.data" %> 
2: <%@ import namespace="system.data.sqlclient" %>
3:
4: <%
5: dim myconnection as sqlconnection
6: dim mycommand as sqlcommand
7: dim firstname as string = "robert"
8: dim lastname as string = "johnson"
9:
10: myconnection = new sqlconnection( "server=localhost;uid=sa;pwd=secret;database=mydata" )
11: myconnection.open()
12: mycommand = new sqlcommand( "insert authors ( firstname, lastname ) http://aspfree.com/chapters/sams/graphics/ccc.gifvalues ( @firstname, @lastname )", myconnection )
13:
14: mycommand.parameters.add( new sqlparameter( "@firstname", http://aspfree.com/chapters/sams/graphics/ccc.gifsqldbtype.varchar, 30 ))
15: mycommand.parameters( "@firstname" ).value = firstname
16:
17: mycommand.parameters.add( new sqlparameter( "@lastname", http://aspfree.com/chapters/sams/graphics/ccc.gifsqldbtype.varchar, 30 ))
18: mycommand.parameters( "@lastname" ).value = lastname
19:
20: mycommand.executenonquery()
21: myconnection.close()
22: %>
23: record inserted!
5.6使用sql parameters(access)
1: <%@ import namespace="system.data" %> 
2: <%@ import namespace="system.data.oledb" %>
3:
4: <%
5: dim myconnection as oledbconnection
6: dim mycommand as oledbcommand
7: dim firstname as string = "robert"
8: dim lastname as string = "johnson"
9:
10: myconnection = new oledbconnection( "provider=microsoft.jet.oledb.4.0;http://aspfree.com/chapters/sams/graphics/ccc.gifdata source=c:/author2.mdb" )
11: myconnection.open()
12: mycommand = new oledbcommand( "insert into authors ( firstname, lastname ) http://aspfree.com/chapters/sams/graphics/ccc.gifvalues ( @firstname, @lastname )", myconnection )
13:
14: mycommand.parameters.add( new oledbparameter( "@firstname", http://aspfree.com/chapters/sams/graphics/ccc.gifoledbtype.varchar, 30 ))
15: mycommand.parameters( "@firstname" ).value = firstname
16:
17: mycommand.parameters.add( new oledbparameter( "@lastname", http://aspfree.com/chapters/sams/graphics/ccc.gifoledbtype.varchar, 30 ))
18: mycommand.parameters( "@lastname" ).value = lastname
19:
20: mycommand.executenonquery()
21: myconnection.close()
22: %>
23: record inserted!
24:
 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 儋州市| 宣城市| 西乌珠穆沁旗| 临武县| 汾阳市| 伊宁县| 静海县| 阳西县| 清水县| 新和县| 尤溪县| 高碑店市| 方正县| 临城县| 平顶山市| 宁远县| 墨竹工卡县| 农安县| 米脂县| 望城县| 普安县| 建昌县| 炎陵县| 双鸭山市| 通海县| 尚义县| 绍兴市| 毕节市| 阳山县| 治县。| 阿拉善右旗| 淮阳县| 永德县| 涿鹿县| 靖边县| 博湖县| 肥东县| 雅江县| 桃园市| 武宁县| 青田县|