login2.ascx

来自「《精通ASP.NET网络编程》附带实例」· ASCX 代码 · 共 56 行

ASCX
56
字号
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
   '单纯的属性
  Public BackColor As String="white"
  'UserID:帐号的属性
  Public Property UserID As String 
   Get
     Return Text1.Text  '传回Text1的内容,成为UserID的属性值
   End Get
   Set
     Text1.Text=Value  '将UserID的属性值设定给Text1
   End Set
  End Property
 'UserID:密码的属性
  Public Property Password As String 
   Get
     Return Text2.Text  '传回Text2的内容,成为Password的属性值
   End Get
   Set
     Text2.Text=Value  '将Password的属性值设定给Text2
   End Set
  End Property
  Public Function IsLoginOK() As Boolean
      Dim Provider, SQL, ConnStr As String
      Provider = "Microsoft.Jet.OLEDB.4.0;"
      ConnStr = "Provider="+Provider+"Data Source="+Server.MapPath( "Sample.mdb" )
      SQL = "Select * From Users Where UserID='"+UserID+"' And Password='"+Password+"'"
      Dim Cmd As OleDbDataAdapter
      Cmd = New OleDbDataAdapter(SQL, ConnStr)
      Dim ds As DataSet = new DataSet()
      Cmd.Fill(ds, "Users")
      Dim dt As DataTable = ds.Tables("Users")
      If dt.Rows.Count > 0 Then
         IsLoginOK = True
      Else 
         IsLoginOK = False
      End If    
  End Function
</script>
<Table BgColor="<%=BackColor%>" BorderColor="Black" Cellspacing="10">
  <tr>
    <td>帐号:</td>
    <td><asp:TextBox id="Text1" runat="server"/></td>
  </tr>
  <tr>
    <td>密码:</td>
    <td><asp:TextBox id="Text2" TextMode="Password" runat="server"/>
    </td>
  </tr>
  <tr>
    <td></td>
    <td><asp:Button Text="登录" runat="server"/></td>
  </tr>
</Table>

⌨️ 快捷键说明

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