I'm trying to add comments to a database. I'm starting with an Access database to be sure I have the code correct before going to the next step. The two files I'm using are Comments.aspx and the code file Comments.aspx.vb.
Here's what I have so far. The contents of Comments.aspx are:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Comments.aspx.vb" Inherits="Comments" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ift.tt/15udxSm transitional.dtd">
<html xmlns="http://ift.tt/lH0Osb">
<head runat="server">
<title>Leave Your Comments</title>
<style type="text/css">
.style2 { width: 250px; }
.style3 { color: #793300; }
</style>
</head>
<body>
<form id="frmComments" runat="server">
<div style="text-align: center">
<h1 class="style3">Please leave your comments below.</h1>
<table align="center">
<tr><td class="style3">
First Name : </td>
<td class="style2">
<asp:TextBox ID="txtFName" runat="server" Width="250px"></asp:TextBox></td> </tr>
<tr> <td class="style3">
Last Name : </td>
<td class="style2">
<asp:TextBox ID="txtLName" runat="server" Width="250px"></asp:TextBox></td></tr>
<tr> <td class="style3">
E-Mail : </td>
<td class="style2">
<asp:TextBox ID="txtEmail" runat="server" Width="250px"></asp:TextBox></td></tr>
<tr> <td class="style3"> Comments : </td>
<td class="style2">
<asp:TextBox ID="txtComments" runat="server" TextMode = "MultiLine" Height="60px" Width="250px"></asp:TextBox></td></tr>
</table>
<br /><asp:ImageButton ID="btnContactUs" runat="server" Height="50px"
ImageUrl="~/Images/Dark_Continue.gif" />
</div>
</form>
</body>
</html>
The contents of Comments.aspx.vb are:
Imports System.Data.OleDb
Partial Class Comments
Inherits System.Web.UI.Page
Private Property FNameParam As Object
Private Property LNameParam As Object
Private Property CommentsParam As Object
Private Property EMailParam As OleDbParameter
Sub ImageButtonRun_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=/Test.mdb"
Dim dbConnection As New OleDbConnection(ConnectionStringSettings)
dbConnection.Open()
Dim commandString As String = "INSERT INTO Contacts(FName, LName, EMail, Comments) " & _
"Values(@FName, @LName, @EMail, @Comments)"
Dim dbCommand As New OleDbCommand(commandString, dbConnection)
Dim FNameParam As New OleDbParameter("@FName", OleDbType.VarChar, 50)
FNameParam.Value = txtFName.Text
dbCommand.Parameters.Add(FNameParam)
Dim LNameParam As New OleDbParameter("@LName", OleDbType.VarChar, 50)
LNameParam.Value = txtLName.Text
dbCommand.Parameters.Add(LNameParam)
Dim EMailParam As New OleDbParameter("@EMail", OleDbType.VarChar, 255)
EMailParam.Value = txtEmail.Text
dbCommand.Parameters.Add(EMailParam)
Dim CommentsParam As New OleDbParameter("@Comments", OleDbType.VarChar, 255)
CommentsParam.Value = txtComments.Text
dbCommand.Parameters.Add(CommentsParam)
dbCommand.ExecuteNonQuery()
dbConnection.Close()
End Sub
Private Function ConnectionStringSettings() As String
Throw New NotImplementedException
End Function
End Class
Absolutely nothing at all happens after I fill in the form and click the image button. Most of what I've read points me in this direction' but it's obviously wrong. Please help.
Aucun commentaire:
Enregistrer un commentaire