A1: | The code for the stored procedure (in Access) is as follows: 1: INSERT INTO tblUsers ( FirstName, LastName, Address, 2: City, State, Zip, Phone ) 3: VALUES (@FirstName, @LastName, @Address, 4: @City, @state, @Zip, @Phone) The code for the ASP.NET page is as follows: 1: <%@ Page Language="VB" %> 2: <%@ Import Namespace="System.Data" %> 3: <%@ Import Namespace="System.Data.OleDb" %> 4: 5: <script runat="server"> 6: 'declare connection 7: dim Conn as new OleDbConnection("Provider=" & _ 8: "Microsoft.Jet.OLEDB.4.0;" & _ 9: "Data Source=c:\ASPNET\data\banking.mdb") 10: 11: sub InsertData(Sender as Object, e as EventArgs) 12: dim objCmd as OleDbCommand = new OleDbCommand _ 13: ("InsertUser", Conn) 14: objCmd.CommandType = CommandType.StoredProcedure 15: 16: dim objParam as OleDbParameter 17: objParam = objCmd.Parameters.Add("@FirstName", _ 18: OleDbType.BSTR) 19: objParam.Direction = ParameterDirection.Input 20: objParam.Value = tbFName.Text 21: 22: objParam = objCmd.Parameters.Add("@LastName", _ 23: OleDbType.BSTR) 24: objParam.Direction = ParameterDirection.Input 25: objParam.Value = tbLName.Text 26: 27: objParam = objCmd.Parameters.Add("@Address", _ 28: OleDbType.BSTR) 29: objParam.Direction = ParameterDirection.Input 30: objParam.Value = tbAddress.Text 31: 32: objParam = objCmd.Parameters.Add("@City", _ 33: OleDbType.BSTR) 34: objParam.Direction = ParameterDirection.Input 35: objParam.Value = tbCity.Text 36: 37: objParam = objCmd.Parameters.Add("@State", _ 38: OleDbType.BSTR) 39: objParam.Direction = ParameterDirection.Input 40: objParam.Value = tbState.Text 41: 42: objParam = objCmd.Parameters.Add("@Zip", _ 43: OleDbType.BSTR) 44: objParam.Direction = ParameterDirection.Input 45: objParam.Value = tbZip.Text 46: 47: objParam = objCmd.Parameters.Add("@Phone", _ 48: OleDbType.BSTR) 49: objParam.Direction = ParameterDirection.Input 50: objParam.Value = tbPhone.Text 51: 52: try 53: objCmd.Connection.Open() 54: objCmd.ExecuteNonQuery 55: catch ex as OleDbException 56: lblMessage.Text = ex.Message 57: end try 58: 59: objCmd.Connection.Close() 60: lblMessage.Text = "User successfully added." 61: end sub 62: </script> 63: 64: <html><body> 65: <form runat="server"> 66: <asp:Label runat="server" 67: maintainstate=false /><br> 68: <asp:Panel runat="server"> 69: <table> 70: <tr> 71: <td width="100" valign="top"> 72: First and last name: 73: </td> 74: <td width="300" valign="top"> 75: <asp:TextBox runat="server" /> 76: <asp:TextBox runat="server" /> 77: </td> 78: </tr> 79: <tr> 80: <td valign="top"> 81: Address: 82: </td> 83: <td valign="top"> 84: <asp:TextBox 85: runat="server" /> 86: </td> 87: </tr> 88: <tr> 89: <td valign="top"> 90: City, State, ZIP: 91: </td> 92: <td valign="top"> 93: <asp:TextBox 94: runat="server" />, 95: <asp:TextBox runat="server" 96: size=2 /> 97: <asp:TextBox runat="server" 98: size=5 /> 99: </td> 100: </tr> 101: <tr> 102: <td valign="top"> 103: Phone: 104: </td> 105: <td valign="top"> 106: <asp:TextBox runat="server" 107: size=11 /><p> 108: </td> 109: </tr> 110: <tr> 111: <td colspan="2" valign="top" align="right"> 112: <asp:Button runat="server" 113: text="Add" 114: OnClick="InsertData" /> 115: </td> 116: </tr> 117: </table> 118: </asp:Panel> 119: </form> 120: </body></html> |