📄 complex-datareader.aspx
字号:
<%@Page Language="VB"%>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.OleDb" %>
<%@ Register TagPrefix="wrox" TagName="connect" Src="..\global\connect-strings.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Extracting Complex Data with a DataReader</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">Extracting Complex Data with a DataReader</span><hr />
<!--------------------------------------------------------------------------->
<%'-- insert connection string script --%>
<wrox:connect id="ctlConnectStrings" runat="server"/>
<div>Connection string: <b><span id="outConnect" runat="server"></span></b></div>
<div>SELECT command: <b><span id="outSelect" runat="server"></span></b></div>
<div id="outError" runat="server"> </div>
<asp:datagrid id="dgrResult" runat="server" />
<script language="vb" runat="server">
Sub Page_Load()
'get connection string from ..\global\connect-strings.ascx user control
Dim strConnect = ctlConnectStrings.OLEDBConnectionString
outConnect.innerText = strConnect 'and display it
'specify the SELECT statement to extract the data
Dim strSelect As String
strSelect = "SELECT BookList.*, BookAuthors.FirstName, BookAuthors.LastName " _
& "FROM BookList INNER JOIN BookAuthors ON BookList.ISBN = BookAuthors.ISBN " _
& "WHERE BookList.ISBN LIKE '18610033%'"
outSelect.innerText = strSelect 'and display it
'declare a variable to hold a DataReader object
Dim objDataReader As OleDbDataReader
Dim objConnect As OleDbConnection
Try
'create a new Connection object using the connection string
objConnect = New OleDbConnection(strConnect)
'create a new Command using the connection object and select statement
Dim objCommand As New OleDbCommand(strSelect, objConnect)
'open the connection and execute the command to return the DataReader
objConnect.Open()
objDataReader = objCommand.ExecuteReader()
Catch objError As Exception
'display error details
outError.innerHTML = "<b>* Error while accessing data</b>.<br />" _
& objError.Message & "<br />" & objError.Source
Exit Sub ' and stop execution
End Try
'assign the DataReader object to the DataGrid control
dgrResult.DataSource = objDataReader
dgrResult.DataBind() 'and bind (display) the data
objConnect.Close() 'then close the connection
'finished with the DataReader
objDataReader = Nothing
End Sub
</script>
<!--------------------------------------------------------------------------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -