ASP.Net/Components/Tip of the Day

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Tip of the Day Demo (VB.net)

   <source lang="csharp">
      

<%-- Code revised from ASP.NET Tips & Techniques (Paperback) by Greg Buczek

  1. Publisher: McGraw-Hill/Osborne Media; 1st edition (May 21, 2002)
  2. Language: English
  3. ISBN: 0072225149

--%>


<%@ Page Language=VB Debug=true %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OLEDB" %> <script runat=server> Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)

   Dim DBConn as OleDbConnection
   Dim DBCommand As OleDbDataAdapter
   Dim DSPageData as New DataSet
   If Application("TipDate") <> Today() Then
       Application("TipDate") = Today()
       If Not Isnumeric(Application("TipNumber")) Then
           Application("TipNumber") = 1
       Else
           Application("TipNumber") = _
               Application("TipNumber") + 1
       End If
   End If
   DBConn = New OleDbConnection( _
       "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
       & "DATA SOURCE=" _
       & Server.MapPath _
       ("TipDB.mdb;"))
   DBCommand = New OleDbDataAdapter _
       ("Select TipTitle, TipText From Tips " _
       & "Where SequenceNumber = " _
       & Application("TipNumber"), DBConn)
   DBCommand.Fill(DSPageData, _
       "TheTip")
   If DSPageData.Tables("TheTip").Rows.Count = 0 Then
       Application("TipNumber") = 1
       DBCommand = New OleDbDataAdapter _
           ("Select TipTitle, TipText From Tips " _
           & "Where SequenceNumber = " _
           & Application("TipNumber"), DBConn)
       DBCommand.Fill(DSPageData, _
           "TheTip")
   End If
   lblTipTitle.Text = _
       DSPageData.Tables("TheTip").Rows(0). _
       Item("TipTitle")
   lblTipText.Text = _
       DSPageData.Tables("TheTip").Rows(0). _
       Item("TipText")

End Sub </SCRIPT> <HTML> <HEAD> <TITLE>Tip of the Day</TITLE> </HEAD> <Body LEFTMARGIN="40"> <form runat="server">

<asp:label

   id="lblTitle" 
   font-size="12pt"
   font-bold="True"
   font-name="Lucida Console"
   runat="server"
   text="Current Tip of the Day"

/>

<asp:label

   id="lblTipTitle" 
   font-size="10pt"
   font-name="Lucida Console"
   runat="server"

/>
<asp:label

   id="lblTipText" 
   font-size="10pt"
   font-name="Lucida Console"
   runat="server"

/> </form> </BODY> </HTML>

      </source>
   
  

<A href="http://www.nfex.ru/Code/ASPDownload/TipDB.zip">TipDB.zip( 8 k)</a>