Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BC30506: Handles clause requires a WithEvents variable.

Status
Not open for further replies.

markdmac

MIS
Dec 20, 2003
12,340
US
I hope someone can assist me here. I've been searching online about the error I am getting but the solutions I am finding all refer to a code behind page which I do not have.

The error I am getting is:
Code:
BC30506: Handles clause requires a WithEvents variable.
Line 15: 	Public Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("\fpdb\guestbook.mdb") & ";"
Line 16: 	
[red]Line 17: 	Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
[/red]Line 18: 		Dim cmd As New OleDbCommand("INSERT INTO [guestlog] ([Firstname], [Lastname], [Email],[Lot],[IP]) VALUES ('" &txtFirstName.Text & "','" & txtLastName.Text & "','" & txtEmail.Text & "','" & txtLot.Text & ClientIP &"')", New OleDbConnection(strConn))
Line 19: 		cmd.Connection.Open()

My page simply grabs data from a form and is supposed to add it to an Access database. Here is the code I have, I hope someone can suggest a fix. Thanks in advance.

Code:
<%@ Page Language="VB" %>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<%@ import Namespace="System.Web.UI.Page" %>
<%
Dim ClientIP, btype
%>
<% ClientIP=Request.ServerVariables("REMOTE_HOST")%>
<% btype=Request.ServerVariables("HTTP_USER_AGENT") %> 
<%
%>
<script runat="server">

	Public Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("\fpdb\guestbook.mdb") & ";"
	
	Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
		Dim cmd As New OleDbCommand("INSERT INTO [guestlog] ([Firstname], [Lastname], [Email],[Lot],[IP]) VALUES ('" &txtFirstName.Text & "','" & txtLastName.Text & "','" & txtEmail.Text & "','" & txtLot.Text & ClientIP &"')", New OleDbConnection(strConn))
		cmd.Connection.Open()
		cmd.ExecuteNonQuery()
		cmd.Connection.Close()
		LoadData()
	End Sub
</script>

	

<html>   
<body<%
If instr(btype,"MSIE") = 0 Then
Response.Write " bgcolor='#559BDA'"
End If
%>>
<div align="center">

	<form id="Form1" method="post" runat="server">
	<p align="center">Spammers Beware!&nbsp; Your IP Address is being recorded.&nbsp; 
	Attempts to spam our Guest Book will be reported to your ISP.<br>
	Your IP Address is: {<% Response.Write(ClientIP) %>}</p>
	<p>
	<br>
	</p>
	<table bordercolor=#559BDA border=1 bgcolor="Gray">
    <tr>
		<td><strong>Sign the Guest Book</strong></td>
	</tr>
    <tr bgcolor="goldenrod">
        <td bgcolor="#99CCFF"><b>First Name</b></td>
        <td bgcolor="#99CCFF"><b>Last Name</b></td>
        <td bgcolor="#99CCFF"><b>E-Mail</b></td>
        <td colspan="2" bgcolor="#99CCFF"><b>Lot Number</b></td>
    </tr>    
    <tr>
    <td><asp:TextBox id="txtFirstName" runat="server" Width="77px"></asp:TextBox></td>
    <td><asp:TextBox id="txtLastName" runat="server" Width="77px"></asp:TextBox></td>
    <td><asp:TextBox id="txtEmail" runat="server"></asp:TextBox></td>
    <td><asp:TextBox id="txtLot" runat="server" Width="345px"></asp:TextBox></td>
    <td><asp:button id="btnInsert" onclick="btnInsert_Click" runat="server" text="Sign Guestbook"></asp:button></td>
    </tr>
    <tr>
    <td colspan="4">
	</td>
	</tr>
    </table>
	</form>

	<p>&nbsp;</p>
	<p>Privacy Notice: Any information you enter on our Web site or give us in 
	any other way will be held in strict confidence. You may choose not to 
	provide certain information. We use the information that you provide for 
	such purposes as responding to your requests, customizing future content, 
	improving our site, and communicating with you.&nbsp; Under no circumstances 
	will the Higley Groves Homeowners Association or its' contracted management 
	company sell, rent or share your information with any outside party without 
	your written consent.</p>
	&nbsp;</td>
</div>
</body>
</html>

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
I did not test before I added in the additional code but will give that a shot.

I am getting this after pasting in the code you specified.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top