473,498 Members | 1,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Insert method problems

Hi there,

I have ASP

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Guestbook.aspx.vb"
Inherits="Guestbook" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<span style="font-family: Verdana"><strong>Guestbook<br />
<br />
</strong>
<table>
<tr>
<td style="width: 100px">
<span style="font-size: 10pt">
FirstName</span></td>
<td style="width: 100px">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
<span style="font-size: 10pt">
LastName</span></td>
<td style="width: 100px">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Button ID="Button1" runat="server" Text="Submit" /></td>
<td style="width: 100px">
</td>
</tr>
</table>
<br />
</span>
<br />
&nbsp;</div>
</form>
</body>
</html>

And VB

Imports System.Data
Imports System.Data.SqlClient
Public Class ProductInfo
Const conString As String = _
"Server=localhost;Trusted_Connection=true;Database =Northwind"
Public Function MyInsertMethod() As Integer
Dim con As New SqlConnection(conString)
Dim insertString As String = "INSERT INTO Guests (FirstName, LastName)
VALUES ('" & FirstName.Text & "','" & LastName.Text & "')"
Dim cmd As New SqlCommand(insertString, con)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Function
End Class
Partial Class Guestbook
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Call MyInsertMethod()
End Sub
End Class

I'm getting an error FirstName must be declared
And Call MyInsertMethod must be declared

How do I fixed that and insert a FirstName and LastNAme into database

Thanks,

Ed Dror


Jan 31 '06 #1
1 1890
Public Function MyInsertMethod(lastName as string , firstName as string) As
Integer

dim p as ProductInfo = new ProductInfo()
p.Insert(Me.TextBox1.Text, Me.TextBox2.Text)

...

You also should clean up some stuff. (you may be doing this... but I don't
know for sure)

Don't hard code your connection string, learn how to store it in the
web.config file.

And check this example:
SqlCommand.Prepare Method
http://msdn.microsoft.com/library/de...QueryTopic.asp

Dim id As Integer = 20
Dim desc As String = "myFirstRegion"
Dim rConn As SqlConnection = New SqlConnection("Persist Security
Info=False;" & _
"Integrated
Security=SSPI;database=northwind;server=mySQLServe r")
rConn.Open()
Dim command As SqlCommand = New SqlCommand("", rConn)

' Create and prepare an SQL statement.
command.CommandText = "insert into Region (RegionID, RegionDescription)
values (@id, @desc)"
command.Parameters.Add("@id", id)
command.Parameters.Add("@desc", desc)
command.Prepare() ' Calling Prepare after having set the Commandtext and
parameters.
command.ExecuteNonQuery()

' Change parameter values and call ExecuteNonQuery.
command.Parameters(0).Value = 21
command.Parameters(1).Value = "mySecondRegion"
command.ExecuteNonQuery()


"Ed Dror" <ed*@andrewlauren.com> wrote in message
news:uq**************@TK2MSFTNGP11.phx.gbl...
Hi there,

I have ASP

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Guestbook.aspx.vb" Inherits="Guestbook" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<span style="font-family: Verdana"><strong>Guestbook<br />
<br />
</strong>
<table>
<tr>
<td style="width: 100px">
<span style="font-size: 10pt">
FirstName</span></td>
<td style="width: 100px">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
<span style="font-size: 10pt">
LastName</span></td>
<td style="width: 100px">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Button ID="Button1" runat="server" Text="Submit" /></td>
<td style="width: 100px">
</td>
</tr>
</table>
<br />
</span>
<br />
&nbsp;</div>
</form>
</body>
</html>

And VB

Imports System.Data
Imports System.Data.SqlClient
Public Class ProductInfo
Const conString As String = _
"Server=localhost;Trusted_Connection=true;Database =Northwind"
Public Function MyInsertMethod() As Integer
Dim con As New SqlConnection(conString)
Dim insertString As String = "INSERT INTO Guests (FirstName, LastName)
VALUES ('" & FirstName.Text & "','" & LastName.Text & "')"
Dim cmd As New SqlCommand(insertString, con)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Function
End Class
Partial Class Guestbook
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Call MyInsertMethod()
End Sub
End Class

I'm getting an error FirstName must be declared
And Call MyInsertMethod must be declared

How do I fixed that and insert a FirstName and LastNAme into database

Thanks,

Ed Dror

Feb 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
6273
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
1
2908
by: Abareblue | last post by:
I have no clue on how to insert a record into access. here is the whole thing using System; using System.Drawing; using System.Collections; using System.ComponentModel;
2
2384
by: Polyhedron_12 | last post by:
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...
3
1814
by: rhaazy | last post by:
Using ms sql 2000 I have 2 tables. I have a table which has information regarding a computer scan. Each record in this table has a column called MAC which is the unique ID for each Scan. The...
5
2720
by: Rob | last post by:
I'm trying to use the set<my_class>::insert( my_class const & ) method, but have run into some problems. It seems like I'm seeing it insert an object when a similar object is already in the set. ...
2
2835
by: =?Utf-8?B?Y2F0?= | last post by:
We recently moved an older ASP.NET 1.1 code base on to ASP.NET 2.0, .NET 3.0 and Windows 2003 Server SP2. We started experiencing the following issue with the web cache (the code is straightforward...
4
2169
by: =?Utf-8?B?RXJpYyBGYWxza2Vu?= | last post by:
We’re storing our main entity in an insert only table which stores the history of past revisions, but we’re facing problems with storing this history as LINQ will only update the entity, and...
2
5017
by: wizardry | last post by:
hello - i'm trying to insert a blob into my table, it will insert but the string that i insert when i query the inserted data returns null with 0 bytes in the column. I have other tables set...
1
2446
by: jpenguin | last post by:
This should be simple, but I'm stuck <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db('joshdye', $con);
0
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5460
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4904
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.