Using Visual Studio 2010 I have created a VB Web Application which I added a database to. I have a VB class which is suppose to take a name and add it to the database through a stored procedure. I run the code and it passes the variable to the vb class but doesn’t seem to change the table once I’ve stopped running the program.
I’m new to the vb and visual studios thing so I’m using http://www.macronimous.com/resources/calling_stored_procedures_from_ASP.NET_and_VB.NET.asp as my guide which is why the code is the way it is.
Here is the vb class
Imports System.Data
Imports System.Data.SqlClient
Public Class human
Private name As String
Private id As Integer
Public Function sendName(ByVal nm As String)
Dim SQLCon As New SqlClient.SqlConnection
Dim SQLCmd As New SqlCommand
SQLCon.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=
C:\Documents and Settings\user\my documents\visual studio 2010\Projects\
WebApplication3\WebApplication3\App_Data\Database1.mdf;
Integrated Security=True;User Instance=True"
SQLCon.Open()
'I want to to execute the procedure addName using the variable nm
SQLCmd.CommandText = "addName"
SQLCmd.CommandType = CommandType.StoredProcedure
SQLCmd.Parameters.AddWithValue("@name", nm)
SQLCmd.Connection = SQLCon 'Active Connection
SQLCon.Close()
Return (nm)
End Function
End Class
and here's my stored procedure "addName"
Alter PROCEDURE addName (@GivenName varchar(100))
AS
BEGIN
SET NOCOUNT ON;
Insert into tableA (name) values (@GivenName);
END
return
What am I missing that prevents the table from showing updates after I stop debugging the application?
Great. You define a command, you create a connection and open it. But you fail to execute the command.