
1.1创建数据库连接(sqlserver)
1: <%@ import namespace="system.data" %>
2: <%@ import namespace="system.data.sqlclient" %>
3: <%
4: dim myconnection as sqlconnection
5: myconnection = new sqlconnection( "server=localhost;database=pubs;uid=sa" )
6:
7: myconnection.open()
8: %>
9: connection opened!
1.2创建数据库连接(access)
1: <%@ import namespace="system.data" %>
2: <%@ import namespace="system.data.oledb" %>
3: <%
4: dim myconnection as oledbconnection
5: myconnection = new oledbconnection( "provider=microsoft.jet.oledb.4.0;data
http://aspfree.com/chapters/sams/graphics/ccc.gifsource=c:\authors.mdb" )
6:
7: myconnection.open()
8: %>
9: connection opened!
2.1添加纪录(sqlserver) 1: <%@ import namespace="system.data" %> 2: <%@ import namespace="system.data.sqlclient" %> 3: 4: <% 5: dim myconnection as sqlconnection 6: dim mycommand as sqlcommand 7: 8: myconnection = new sqlconnection( "server=localhost;uid=sa;database=pubs" ) 9: myconnection.open() 10: mycommand = new sqlcommand( "insert testtable ( col1 ) http://aspfree.com/chapters/sams/graphics/ccc.gifvalues ( hello )", myconnection ) 11: mycommand.executenonquery() 12: myconnection.close() 13: %> 14: new record inserted! 15: 2.2添加纪录(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: 8: myconnection = new oledbconnection( "provider=microsoft.jet.oledb.4.0;data http://aspfree.com/chapters/sams/graphics/ccc.gifsource=c:authors.mdb" ) 9: myconnection.open() 10: mycommand = new oledbcommand( "insert into authors ( author ) values http://aspfree.com/chapters/sams/graphics/ccc.gif( simpson )", myconnection ) 11: mycommand.executenonquery() 12: myconnection.close() 13: %> 14: new record inserted! 15: 3.1更新数据(sqlserver) 1: <%@ import namespace="system.data" %> 2: <%@ import namespace="system.data.sqlclient" %> 3: 4: <% 5: dim myconnection as sqlconnection 6: dim mycommand as sqlcommand 7: 8: myconnection = new sqlconnection( "server=localhost;uid=sa;database=pubs" ) 9: myconnection.open() 10: mycommand = new sqlcommand( "update authors set lastname=smith http://aspfree.com/chapters/sams/graphics/ccc.gifwhere lastname=bennett", myconnection ) 11: mycommand.executenonquery() 12: myconnection.close() 13: %> 14: record updated! 15: 3.2更新数据(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: 8: myconnection = new oledbconnection( "provider=microsoft.jet.oledb.4.0;data http://aspfree.com/chapters/sams/graphics/ccc.gifsource=c:\authors.mdb" ) 9: myconnection.open() 10: mycommand = new oledbcommand( "update authors set author=bennett http://aspfree.com/chapters/sams/graphics/ccc.gifwhere author = simpson", myconnection ) 11: mycommand.executenonquery() 12: myconnection.close 13: %> 14: record updated!15: 3.3更新数据中受影响的记录数 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 recordsaffected as integer
8:
9: myconnection = new sqlconnection( "server=localhost;uid=sa;database=pubs" )
10: myconnection.open()
11: mycommand = new sqlcommand( "update testtable set col1=hello http://aspfree.com/chapters/sams/graphics/ccc.gifwhere col1=fred", myconnection )
12: recordsaffected = mycommand.executenonquery()
13: response.write( "the update statement modified " & http://aspfree.com/chapters/sams/graphics/ccc.gifrecordsaffected.tostring() & " records!" )
14: myconnection.close
15: %>
16: 4.1删除数据(sqlserver) 1: <%@ import namespace="system.data" %>
2: <%@ import namespace="system.data.sqlclient" %>
3:
4: <%
5: dim myconnection as sqlconnection
6: dim mycommand as sqlcommand
7:
8: myconnection = new sqlconnection( "server=localhost;uid=sa;database=pubs" )
9: myconnection.open()
10: mycommand = new sqlcommand( "delete testtable where col1=fred", myconnection )
11: mycommand.executenonquery()
12: myconnection.close()
13: %>
14: record deleted!
15: 4.2删除数据(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:
8: myconnection = new oledbconnection( "provider=microsoft.jet.oledb.4.0;data http://aspfree.com/chapters/sams/graphics/ccc.gifsource=c:\authors.mdb" )
9: myconnection.open()
10: mycommand = new oledbcommand( "delete from authors http://aspfree.com/chapters/sams/graphics/ccc.gifwhere author = simpson", myconnection )
11: mycommand.executenonquery()
12: myconnection.close()
13: %>
14: record deleted!
15:
16: 4.3删除纪录中受影响的记录数 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 recordsaffected as integer 8: 9: myconnection = new sqlconnection( "server=localhost;uid=sa;database=pubs" ) 10: myconnection.open() 11: mycommand = new sqlcommand( "delete authors2 http://aspfree.com/chapters/sams/graphics/ccc.gifwhere lastname=smith", myconnection ) 12: recordsaffected = mycommand.executenonquery() 13: response.write( "the delete statement modified " http://aspfree.com/chapters/sams/graphics/ccc.gif& recordsaffected.tostring() & " records!" ) 14: myconnection.close 15: %> 16:
|