G
Guest
I am having trouble figuring out to call a database INSERT procedure from a
simple submit form.
It appears I should use the onclick event to trigger the procedure called
[Sub btnInsert_Click] BUT when I do this I receive this error:
'btnInsert_Click' is not a member of 'ASP.Insert_aspx'.
I realise the procedure is houwsed in a [Private] sub which may be what is
causing the problem, but I am stumped on how to connect the form to the .NET
code...
Could someone help me here?
<% @ Import namespace="System.Data.SqlClient" %>
<script runat="server">
'Imports System.Data.SqlClient
Public Class index
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents btnInsert As System.Web.UI.WebControls.Button
Protected WithEvents txtFirstName As System.Web.UI.WebControls.TextBox
Protected WithEvents txtLastName As System.Web.UI.WebControls.TextBox
Protected WithEvents Repeater1 As System.Web.UI.WebControls.Repeater
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Public strConn As String = "data source=xx.xx.xxx.xxx; User ID=xxxxxx;
Password=xxxxxx; Persist Security Info=True;packet size=4096"
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
LoadData()
End Sub
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnInsert.Click
Dim strConn As String = "data source=test.maximumasp.com; User
ID=V03testUW; Password=test Persist Security Info=True;packet size=4096"
Dim cmd As New SqlCommand("INSERT INTO ChangeStatus (FirstName,
LastName)VALUES('" & txtFirstName.Text & "','" & txtLastName.Text & "')",
New SqlConnection(strConn))
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
LoadData()
End Sub
Sub LoadData()
Dim strConn As String = "data source=test.maximumasp.com; User ID=test;
Password=testJ; Persist Security Info=True;packet size=4096"
Dim strSQL As String = "Select * From Customers"
Dim cmd As New SqlCommand(strSQL, New SqlConnection(strConn))
cmd.Connection.Open()
Repeater1.DataSource = cmd.ExecuteReader
Repeater1.DataBind()
cmd.Connection.Close()
cmd.Connection.Dispose()
End Sub
End Class' Insert page code here
'
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:TextBox id="txtFirstName" runat="server"></asp:TextBox>
</p>
<p>
</p>
<p>
<asp:TextBox id="txtLastName" runat="server"></asp:TextBox>
<asp:Button id="Button1" onclick="Button1_Click" runat="server"
Text="Button"></asp:Button>
</p>
</form>
</body>
</html>
simple submit form.
It appears I should use the onclick event to trigger the procedure called
[Sub btnInsert_Click] BUT when I do this I receive this error:
'btnInsert_Click' is not a member of 'ASP.Insert_aspx'.
I realise the procedure is houwsed in a [Private] sub which may be what is
causing the problem, but I am stumped on how to connect the form to the .NET
code...
Could someone help me here?
<% @ Import namespace="System.Data.SqlClient" %>
<script runat="server">
'Imports System.Data.SqlClient
Public Class index
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents btnInsert As System.Web.UI.WebControls.Button
Protected WithEvents txtFirstName As System.Web.UI.WebControls.TextBox
Protected WithEvents txtLastName As System.Web.UI.WebControls.TextBox
Protected WithEvents Repeater1 As System.Web.UI.WebControls.Repeater
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Public strConn As String = "data source=xx.xx.xxx.xxx; User ID=xxxxxx;
Password=xxxxxx; Persist Security Info=True;packet size=4096"
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
LoadData()
End Sub
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnInsert.Click
Dim strConn As String = "data source=test.maximumasp.com; User
ID=V03testUW; Password=test Persist Security Info=True;packet size=4096"
Dim cmd As New SqlCommand("INSERT INTO ChangeStatus (FirstName,
LastName)VALUES('" & txtFirstName.Text & "','" & txtLastName.Text & "')",
New SqlConnection(strConn))
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
LoadData()
End Sub
Sub LoadData()
Dim strConn As String = "data source=test.maximumasp.com; User ID=test;
Password=testJ; Persist Security Info=True;packet size=4096"
Dim strSQL As String = "Select * From Customers"
Dim cmd As New SqlCommand(strSQL, New SqlConnection(strConn))
cmd.Connection.Open()
Repeater1.DataSource = cmd.ExecuteReader
Repeater1.DataBind()
cmd.Connection.Close()
cmd.Connection.Dispose()
End Sub
End Class' Insert page code here
'
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:TextBox id="txtFirstName" runat="server"></asp:TextBox>
</p>
<p>
</p>
<p>
<asp:TextBox id="txtLastName" runat="server"></asp:TextBox>
<asp:Button id="Button1" onclick="Button1_Click" runat="server"
Text="Button"></asp:Button>
</p>
</form>
</body>
</html>