欢迎光临
我们一直在努力

建站超值云服务器,限时71元/月

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:
 
赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 »
分享到: 更多 (0)

相关推荐

  • 暂无文章