ASP.NET Need Help With WEB MATRIX Insert

P

Polyhedron_12

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(connectionString)

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
 
S

Sarika [MSFT]

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(connectionString)

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: (e-mail address removed) (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: <[email protected]>
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: (e-mail address removed)
NNTP-Posting-Date: Thu, 9 Oct 2003 15:25:54 +0000 (UTC)
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!postnews1.google.com!no
t-for-mail
Xref: 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(connectionString)

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top