📄 ex23vb.aspx
字号:
<% @ Page Language="VB" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OleDb" %>
<html>
<head>
<title>第二十三例 数据库的简单查询实例</title>
<Script Language="VB" Runat="Server">
Dim public myConnstring as string = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("aspnet.mdb")
Dim MyConnection as OleDbConnection
'定义连接的字符串为公共变量,利于多次访问
public Sub Page_Load(sender As Object,e As EventArgs)
Dim selstr as string ="Select * from Student Order by ID"
try
MyConnection = new OleDbConnection(myConnstring)
'设定联结
Dim MyCommand as OleDbCommand = new OleDbCommand(selstr,MyConnection)
MyConnection.Open()
'打开连接
Dim MyDataReader as OleDbDataReader = MyCommand.ExecuteReader()
'数据的读取
DataGrid1.DataSource=myDataReader
DataGrid1.DataBind()
'与DataGrid的数据绑定
MyDataReader.Close()
MyConnection.Close()
'关闭联结
Info.Text="Student表中的数据:"
catch ee As Exception
Info.Text="发生错误:"+ee.Message
'联结出错时,出错信息的获取
finally
End try
End Sub
</script>
</head>
<body>
<h3><font face="Verdana">第二十三例 数据库的简单查询实例</font></h3>
<font color=red><b><asp:Label id="Info" runat=server /></b></font><br>
<form runat="server">
<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"
/>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -