By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,824 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

ASP.NET Need Help With WEB MATRIX Insert

P: n/a
I am having problems calling functions in general in VB. I keep
getting alot of errors. Can anybody help me out with this? I put the
error message on the same line that it says it is at. I believe that I
am not calling the function correctly.

The MyInsertMethod function is the function that comes in the Web
Matrix Toolbox
<%@ Page Language="VB" %>
<script runat="server">

' Insert page code here
Function MyInsertMethod(ByVal tier1Name As String) As Integer
Dim connectionString As String = "server='(local)'; user
id='sa'; password='ladiedah'; database='accessory'"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)

Dim queryString As String = "INSERT INTO [Tier1]
([tier1Name]) VALUES (@tier1Name)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_tier1Name As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_tier1Name.ParameterName = "@tier1Name"
dbParam_tier1Name.Value = tier1Name
dbParam_tier1Name.DbType =
System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_tier1Name)

Dim rowsAffected As Integer = 0
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try

Return rowsAffected
Label1.Text = "Hello2"
End Function

Sub Page_Load
Label1.Text = "Hello"
End Sub

'

</script>
<html>
<head>
</head>
<body>
<form onsubmit="MyInsertMethod(TextBox1.Text)" runat="server">
<p>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:Button id="Button1" onclick="MyInsertMethod
TextBox1.Text" runat="server" Text="Add Tier"></asp:Button> 'BC30408:
Method 'Public Function MyInsertMethod(tier1Name As String) As
Integer' does not have the same signature as delegate 'Delegate Sub
EventHandler(sender As Object, e As System.EventArgs)
</p>
<p>
<asp:Label id="Label1" runat="server">Label</asp:Label>
</p>
<!-- Insert content here -->
</form>
</body>
</html>

Thank You,
Matt Saragusa
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Matt,
The following sample is a good source of
understanding functionality of event handling on the buttons in web form.

ms-help://MS.VSCC/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfSystemWebUIWebCont
rolsButtonClassOnClickTopic.htm

Here is the modified code that get past the error you were experienceing.
Hope this helps.
Thanks,
Sarika

<%@ Page Language="VB" %>
<HTML>
<HEAD>
<script runat="server">

' Insert page code here
Sub SubmitBtn_Click(sender As Object, e As EventArgs)
Message.Text = "Hello World!!"
MyInsertMethod(TextBox1.Text)
End Sub 'SubmitBtn_Click
Function MyInsertMethod(ByVal tier1Name As String) As Integer
Dim connectionString As String = "server='(local)';
userid='sa'; password='ladiedah'; database='accessory'"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)

Dim queryString As String = "INSERT INTO [Tier1]([tier1Name])
VALUES (@tier1Name)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_tier1Name As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_tier1Name.ParameterName = "@tier1Name"
dbParam_tier1Name.Value = tier1Name
dbParam_tier1Name.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_tier1Name)

Dim rowsAffected As Integer = 0
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try

Return rowsAffected
Label1.Text = "Hello2"
End Function

Sub Page_Load
Label1.Text = "Hello"
End Sub
</script>
</HEAD>
<body>
<form onsubmit="MyInsertMethod(TextBox1.Text)" runat="server" ID="Form2">
<p>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:Button id="Button1" onclick="SubmitBtn_Click" runat="server"
Text="Add Tier"></asp:Button>
'BC30408: Method 'Public Function MyInsertMethod(tier1Name As String)
As
Integer' does not have the same signature as delegate 'Delegate Sub
EventHandler(sender As Object, e As System.EventArgs)
</p>
<p>
<asp:Label id="Label1" runat="server">Label</asp:Label>
</p>
<asp:label id="Message" runat="server"/>

<!-- Insert content here -->
</form>
</body>
</HTML>

--------------------
From: po***********@yahoo.com (Polyhedron_12)
Newsgroups: microsoft.public.dotnet.languages.vb
Subject: ASP.NET Need Help With WEB MATRIX Insert
Date: 9 Oct 2003 08:25:54 -0700
Organization: http://groups.google.com
Lines: 78
Message-ID: <7d**************************@posting.google.com >
NNTP-Posting-Host: 68.159.1.146
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1065713154 20676 127.0.0.1 (9 Oct 2003 15:25:54 GMT)X-Complaints-To: gr**********@google.com
NNTP-Posting-Date: Thu, 9 Oct 2003 15:25:54 +0000 (UTC)
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!postnew s1.google.com!no
t-for-mailXref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:145354
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I am having problems calling functions in general in VB. I keep
getting alot of errors. Can anybody help me out with this? I put the
error message on the same line that it says it is at. I believe that I
am not calling the function correctly.

The MyInsertMethod function is the function that comes in the Web
Matrix Toolbox
<%@ Page Language="VB" %>
<script runat="server">

' Insert page code here
Function MyInsertMethod(ByVal tier1Name As String) As Integer
Dim connectionString As String = "server='(local)'; user
id='sa'; password='ladiedah'; database='accessory'"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStr ing)

Dim queryString As String = "INSERT INTO [Tier1]
([tier1Name]) VALUES (@tier1Name)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_tier1Name As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_tier1Name.ParameterName = "@tier1Name"
dbParam_tier1Name.Value = tier1Name
dbParam_tier1Name.DbType =
System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_tier1Name)

Dim rowsAffected As Integer = 0
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try

Return rowsAffected
Label1.Text = "Hello2"
End Function

Sub Page_Load
Label1.Text = "Hello"
End Sub

'

</script>
<html>
<head>
</head>
<body>
<form onsubmit="MyInsertMethod(TextBox1.Text)" runat="server">
<p>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:Button id="Button1" onclick="MyInsertMethod
TextBox1.Text" runat="server" Text="Add Tier"></asp:Button> 'BC30408:
Method 'Public Function MyInsertMethod(tier1Name As String) As
Integer' does not have the same signature as delegate 'Delegate Sub
EventHandler(sender As Object, e As System.EventArgs)
</p>
<p>
<asp:Label id="Label1" runat="server">Label</asp:Label>
</p>
<!-- Insert content here -->
</form>
</body>
</html>

Thank You,
Matt Saragusa


Nov 20 '05 #2

P: n/a
Yay!

It works. And the link was helpful too!

Matt
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.