欢迎光临
我们一直在努力

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

8.1创建一个(主/祥)表关联
1: <%@ import namespace="system.data" %>
2: <%@ import namespace="system.data.sqlclient" %>
3:
4: <%
5: dim myconnection as sqlconnection
6: dim mydataadapter as sqldataadapter
7: dim mydataset as dataset
8: dim mydatatable as datatable
9: dim publisher as datarow
10: dim title as datarow
11:
12: myconnection = new sqlconnection( "server=localhost;uid=sa;pwd=secret;database=pubs" )
13: mydataset = new dataset()
14: mydataadapter = new sqldataadapter( "select * from publishers",
http://aspfree.com/chapters/sams/graphics/ccc.gifmyconnection )
15: mydataadapter.fill( mydataset, "publishers" )
16: mydataadapter.selectcommand = new sqlcommand( "select * from titles",
http://aspfree.com/chapters/sams/graphics/ccc.gifmyconnection )
17: mydataadapter.fill( mydataset, "titles" )
18:
19: mydataset.relations.add( "pubtitles",
http://aspfree.com/chapters/sams/graphics/ccc.gifmydataset.tables( "publishers" ).columns( "pub_id" ),
http://aspfree.com/chapters/sams/graphics/ccc.gifmydataset.tables( "titles" ).columns( "pub_id" ) )
20:
21: for each publisher in mydataset.tables( "publishers" ).rows
22:  response.write( "<p>" & publisher( "pub_name" ) & ":" )
23:  for each title in publisher.getchildrows( "pubtitles" )
24:   response.write("<li>" & title( "title" ) )
25:  next
26: next
27:
28: %>
29:
9.1使用dataadapter update模式
1: <%@ import namespace="system.data" %>
2: <%@ import namespace="system.data.sqlclient" %>
3:
4: <%
5: dim myconnection as sqlconnection
6: dim mydataadapter as sqldataadapter
7: dim mybuilder as sqlcommandbuilder
8: dim mydataset as dataset
9: dim mydatatable as datatable
10: dim author as datarow
11:
12: create the dataset and dataadapter
13: myconnection = new sqlconnection( "server=localhost;uid=sa;pwd=secret;database=pubs" )
14: mydataset = new dataset()
15: mydataadapter = new sqldataadapter( "select * from author", myconnection )
16: mydataadapter.fill( mydataset, "authors" )
17:
18: change value of first row
19: mydataset.tables( "authors" ).rows( 0 ).item( "au_fname" ) = "jane"
20:
21: update the database table
22: mybuilder = new sqlcommandbuilder( mydataadapter )
23: mydataadapter.update( mydataset, "authors" )
24:
25: display the records
26: for each author in mydataset.tables( "authors" ).rows
27:  response.write( "<p>" & author( "au_fname" ) & " "
http://aspfree.com/chapters/sams/graphics/ccc.gif& author( "au_lname" ) )
28: next
29: %>
30:
9.2使用dataadapter update模式(c#)

 
1: <%@ page language="c#" %>
2: <%@ import namespace="system.data" %>
3: <%@ import namespace="system.data.sqlclient" %>
4:
5: <%
6: // create the dataset and dataadapter
7: sqlconnection myconnection = new
http://aspfree.com/chapters/sams/graphics/ccc.gifsqlconnection( "server=localhost;uid=sa;pwd=secret;database=pubs" );
8: dataset mydataset = new dataset();
9: sqldataadapter mydataadapter = new sqldataadapter(
http://aspfree.com/chapters/sams/graphics/ccc.gif"select * from authors3", myconnection );
10: mydataadapter.fill( mydataset, "authors" );
11:
12: // change value of first row
13: mydataset.tables[ "authors" ].rows[ 0 ][ "au_fname" ] = "jane";
14:
15: // update the database table
16: sqlcommandbuilder mybuilder = new sqlcommandbuilder( mydataadapter );
17: mydataadapter.update( mydataset, "authors" );
18:
19: // display the records
20: foreach ( datarow author in mydataset.tables[ "authors" ].rows )
21: {
22:  response.write( "<p>" + author[ "au_fname" ] + " "
http://aspfree.com/chapters/sams/graphics/ccc.gif+ author[ "au_lname" ] );
23: }
24: %>
25:
赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 »
分享到: 更多 (0)

相关推荐

  • 暂无文章