⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex25-1vb.aspx

📁 突破ASP.NET编程实例五十讲源码
💻 ASPX
字号:
<% @ Page Language="VB" Debug="true" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OleDb" %>
<html>
<head>
<title>第二十五例 通过DataAdapter和DataSet访问数据库</title>

<Script Language="VB" Runat="Server">
	public Sub Page_Load(sender as Object,e as EventArgs)
	if RadioButtonList1.SelectedIndex = -1 then
		RadioButtonList1.SelectedIndex = 0
	End if
	End Sub
	'第一次装载页面时,控制RadioButtonList有一个选择
	
	public Sub RadioChange(sender as Object,e as EventArgs)
	if RadioButtonList1.SelectedIndex = 0 then
		Select1("Select * from Student")
	Else if RadioButtonList1.SelectedIndex = 1 then
		Select1("Select * from Book")
	End if
	End Sub
	'RadioButtonList选择项改变时触发该事件

	Function Select1(SqlStr as String)
	Dim MyConnString As string = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("aspnet.mdb")
	Dim MyConnection as OleDbConnection = new OleDbConnection(MyConnString)
	'建立与数据库的联结
	Dim MyComm as OleDbDataAdapter = new OleDbDataAdapter(SqlStr,MyConnection)
	Dim MyDataSet as DataSet = new DataSet()
	'定义MyDataSet
	MyComm.Fill(MyDataSet,"Table1")
	'将查询结果存入Dataset,命名表为Table1
	Myconnection.Close()
	'关闭与数据库的联结
	DataGrid1.DataSource = MyDataSet.Tables("Table1").DefaultView
	DataGrid1.DataBind()
	'数据绑定
	Label1.text = "本数据表中共有<font size=+2 color=red>" + MyDataset.tables("Table1").DefaultView.Count.toString + "</font>条记录"
	End Function
	'访问数据库函数
</script>

</head>
<body>
	<h3><font face="Verdana">第二十五例 通过DataAdapter和DataSet访问数据库</font></h3>
	<form runat=server>
	<asp:Label id=info runat=server text="" />选择您要查询的数据表:
	<asp:RadioButtonList id=RadioButtonList1 runat="server" AutoPostBack=true OnSelectedIndexChanged="RadioChange">
	   <asp:ListItem>Student</asp:ListItem>
	   <asp:ListItem>Book</asp:ListItem>
	</asp:RadioButtonList>
	<ASP:DataGrid id="DataGrid1" runat="server" BorderColor="black" BorderWidth="1" GridLines="Both" CellPadding="3" CellSpacing="0" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" AlternatingItemStyle-BackColor="#eeeeee"/>
	<asp:Label id=Label1 runat=server text="" />
	</form>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -