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

📄 cacheemployees.aspx

📁 asp.net技术内幕的书配源码
💻 ASPX
字号:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<Script Runat="Server">

Sub Button_Click( s As Object, e As EventArgs )
  Dim dstEmployees As DataSet
  Dim conNorthwind As SqlConnection
  Dim dadEmployees As SqlDataAdapter
  Dim dvwEmployees As DataView
  Dim arrValues( 1 ) As Object
  Dim intEmployeeIndex As Integer

  ' Get cached DataView
  dvwEmployees = Cache( "Employees" )
  If dvwEmployees Is Nothing Then
    dstEmployees = New DataSet()
    conNorthwind = New SqlConnection( "Server=localhost;UID=sa;PWD=secret;Database=Northwind" )
    dadEmployees = New SqlDataAdapter( "Select * From Employees", conNorthwind )
    dadEmployees.Fill( dstEmployees, "Employees" )
    dvwEmployees = dstEmployees.Tables( "Employees" ).DefaultView()
    dvwEmployees.Sort = "LastName, FirstName"
    Cache( "Employees" ) = dvwEmployees
  End If

  ' Find the employee
  arrValues( 0 ) = txtLastName.Text
  arrValues( 1 ) = txtFirstName.Text
  intEmployeeIndex = dvwEmployees.Find( arrValues )
  If intEmployeeIndex <> -1 Then
    lblName.Text = txtLastName.Text & ", " & txtFirstName.Text
    lblPhone.Text = dvwEmployees( intEmployeeIndex ).Row( "HomePhone" )
    lblNotes.Text = dvwEmployees( intEmployeeIndex ).Row( "Notes" )
  Else
    lblError.Text = "Employee Not Found!"
  End If
End Sub

</Script>

<html>
<head><title>CacheEmployees.aspx</title></head>
<body>

<h2>Employee Directory</h2>

<form Runat="Server">
<b>First Name:</b>
<asp:TextBox
  ID="txtFirstName"
  Runat="Server" />
<p>
<b>Last Name:</b>
<asp:TextBox
  ID="txtLastName"
  Runat="Server" />
<asp:Button
  Text="Find!"
  OnClick="Button_Click"
  Runat="Server" />
<hr>
<asp:Label
  ID="lblError"
  ForeColor="Red"
  EnableViewState="False"
  Runat="Server" />
<asp:Label
  ID="lblName"
  EnableViewState="False"
  Runat="Server" />
<p>
<asp:Label
  ID="lblPhone"
  EnableViewState="False"
  Runat="Server" />
<p>
<asp:Label
  ID="lblNotes"
  EnableViewState="False"
  Runat="Server" />
</form>

</body>
</html>

⌨️ 快捷键说明

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