?? ex23vb.aspx
字號:
<% @ Page Language="VB" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OleDb" %>
<html>
<head>
<title>第二十三例 數(shù)據(jù)庫的簡單查詢實例</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)
'設(shè)定聯(lián)結(jié)
Dim MyCommand as OleDbCommand = new OleDbCommand(selstr,MyConnection)
MyConnection.Open()
'打開連接
Dim MyDataReader as OleDbDataReader = MyCommand.ExecuteReader()
'數(shù)據(jù)的讀取
DataGrid1.DataSource=myDataReader
DataGrid1.DataBind()
'與DataGrid的數(shù)據(jù)綁定
MyDataReader.Close()
MyConnection.Close()
'關(guān)閉聯(lián)結(jié)
Info.Text="Student表中的數(shù)據(jù):"
catch ee As Exception
Info.Text="發(fā)生錯誤:"+ee.Message
'聯(lián)結(jié)出錯時,出錯信息的獲取
finally
End try
End Sub
</script>
</head>
<body>
<h3><font face="Verdana">第二十三例 數(shù)據(jù)庫的簡單查詢實例</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>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -