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

📄 exercise1.aspx

📁 asp入门到精通的源代码
💻 ASPX
字号:
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script runat="server">
   'declare connection
   dim Conn as new OleDbConnection("Provider=" & _
            "Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=C:\ASPNET\data\banking.mdb")
   
   sub InsertData(obj as Object, e as EventArgs) 
      dim objCmd as OleDbCommand = new OleDbCommand _
         ("InsertUser", Conn)
      objCmd.CommandType = CommandType.StoredProcedure
      
      dim objParam as OleDbParameter
      objParam = objCmd.Parameters.Add("@FirstName", OleDbType.BSTR)
      objParam.Direction = ParameterDirection.Input
      objParam.Value = tbFName.Text
      
      objParam = objCmd.Parameters.Add("@LastName", OleDbType.BSTR)
      objParam.Direction = ParameterDirection.Input
      objParam.Value = tbLName.Text
      
      objParam = objCmd.Parameters.Add("@Address", OleDbType.BSTR)
      objParam.Direction = ParameterDirection.Input
      objParam.Value = tbAddress.Text
      
      objParam = objCmd.Parameters.Add("@City", OleDbType.BSTR)
      objParam.Direction = ParameterDirection.Input
      objParam.Value = tbCity.Text
      
      objParam = objCmd.Parameters.Add("@State", OleDbType.BSTR)
      objParam.Direction = ParameterDirection.Input
      objParam.Value = tbState.Text
      
      objParam = objCmd.Parameters.Add("@Zip", OleDbType.BSTR)
      objParam.Direction = ParameterDirection.Input
      objParam.Value = tbZip.Text
      
      objParam = objCmd.Parameters.Add("@Phone", OleDbType.BSTR)
      objParam.Direction = ParameterDirection.Input
      objParam.Value = tbPhone.Text
      
      try
         objCmd.Connection.Open()
         objCmd.ExecuteNonQuery
      catch ex as OleDbException
         lblMessage.Text = ex.Message
      end try

      objCmd.Connection.Close()
      lblMessage.Text = "User successfully added."
   end sub
</script>

<html><body>
   <form runat="server">
      <asp:Label id="lblMessage" runat="server"
         maintainstate=false /><br>
      <asp:Panel id="Panel1" runat="server">
         <table>
         <tr>
            <td width="100" valign="top">
               First and last name:
            </td>
            <td width="300" valign="top">
               <asp:TextBox id="tbFName" runat="server" />
               <asp:TextBox id="tbLName" runat="server" />
            </td>
         </tr>
         <tr>
            <td valign="top">
               Address: 
            </td>
            <td valign="top">
               <asp:TextBox id="tbAddress" 
                  runat="server" />
            </td>
         </tr>
         <tr>
            <td valign="top">
               City, State, ZIP: 
            </td>
            <td valign="top">
               <asp:TextBox id="tbCity" 
                  runat="server" />,
               <asp:TextBox id="tbState" runat="server"
                  size=2 />&nbsp;
               <asp:TextBox id="tbZIP" runat="server"
                  size=5 />
            </td>
         </tr>
         <tr>
            <td valign="top">
               Phone:          
            </td>
            <td valign="top">
               <asp:TextBox id="tbPhone" runat="server"
                  size=11 /><p>
            </td>
         </tr>
         <tr>
            <td colspan="2" valign="top" align="right">
               <asp:Button id="Submit" runat="server" 
                  text="Add"
                  OnClick="InsertData" />
            </td>
         </tr>
         </table>
      </asp:Panel>
   </form>
</body></html>

⌨️ 快捷键说明

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