<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-659185728455111653</id><updated>2012-02-16T11:14:05.153-08:00</updated><title type='text'>insert into database</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://insertintodb.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/659185728455111653/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://insertintodb.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>RiaQ</name><uri>http://www.blogger.com/profile/02219056924149750665</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-659185728455111653.post-7049835207891444348</id><published>2009-01-28T08:48:00.001-08:00</published><updated>2009-01-28T08:48:08.409-08:00</updated><title type='text'></title><content type='html'>I am facing a huge problem. I did a registration page and i want to store the data into SQL Server. I created two stored procedures in SQL and two functions in visual basic to call the stored procedures before inserting the data into the database. My codes are based on http://daniweb.com/tutorials/tutorial23605.html &lt;br /&gt;&lt;br /&gt;After the execution of codes, the page redirected to a registration successful page and i have checked my SQL connection which i am sure is not the issue. But, my database table remains empty&lt;br /&gt;&lt;br /&gt;First of all, my table is made up of 8 columns, username, password, membername, member date of birth, identification pass, member address, member phone and member email.&lt;br /&gt;&lt;br /&gt;Would someone kindly debug the problem and explain what is wrong with my codes, PLEASE :cry: &lt;br /&gt;&lt;br /&gt;The two stored procedures i created are as followed:&lt;br /&gt;sp_CheckFor Duplicates&lt;br /&gt;CREATE PROCEDURE sp_CheckForDuplicates&lt;br /&gt;(&lt;br /&gt;@MemberUserName VARCHAR(50) = NULL,&lt;br /&gt;@MemberPassword VARCHAR(50) = NULL,&lt;br /&gt;@MemberName VARCHAR(50) = NULL,&lt;br /&gt;@MemberDOB VARCHAR(50) = NULL,&lt;br /&gt;@NRIC VARCHAR(50) = NULL,&lt;br /&gt;@MemberAddress VARCHAR(50) = NULL,&lt;br /&gt;@MemberEmail VARCHAR(50) = NULL,&lt;br /&gt;@MemberPhone VARCHAR(50)=Null,&lt;br /&gt;@Duplicates INT =0&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;AS&lt;br /&gt;SET @Duplicates =(SELECT COUNT(*) FROM Member1&lt;br /&gt;WHERE MemberUserName = @MemberUserName&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;OR MemberPassword = @MemberPassword&lt;br /&gt;OR MemberName = @MemberName&lt;br /&gt;OR MemberDOB =@MemberDOB&lt;br /&gt;OR NRIC =@NRIC&lt;br /&gt;OR MemberAddress = @MemberAddress&lt;br /&gt;AND MemberEmail = @MemberEmail) &lt;br /&gt;RETURN @Duplicates&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;sp_RegisterNewUser&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;CREATE PROCEDURE sp_RegisterNewUser&lt;br /&gt;(&lt;br /&gt;@MemberUserName VARCHAR(50) = NULL,&lt;br /&gt;@MemberPassword VARCHAR(50) = NULL,&lt;br /&gt;@MemberName VARCHAR(50) = NULL,&lt;br /&gt;@MemberDOB VARCHAR(50) = NULL,&lt;br /&gt;@NRIC VARCHAR(50) = NULL,&lt;br /&gt;@MemberAddress VARCHAR(50) = NULL,&lt;br /&gt;@MemberPhone VARCHAR(50) =NULL,&lt;br /&gt;@MemberEmail VARCHAR(50) = NULL&lt;br /&gt;)&lt;br /&gt;AS&lt;br /&gt;IF @MemberUserName IS NULL OR &lt;br /&gt;@MemberPassword IS NULL OR &lt;br /&gt;@MemberName IS NULL OR &lt;br /&gt;@MemberDOB IS NULL OR&lt;br /&gt;@NRIC IS NULL OR&lt;br /&gt;@MemberAddress IS NULL OR&lt;br /&gt;@MemberPhone IS NULL OR &lt;br /&gt;@MemberEmail IS NULL &lt;br /&gt;RAISERROR('Please fill in all fields', 16, 1)&lt;br /&gt;ELSE&lt;br /&gt;BEGIN&lt;br /&gt;INSERT INTO Member1&lt;br /&gt;(MemberUserName, MemberPassword, MemberName, MemberDOB, NRIC, MemberAddress, MemberPhone, MemberEmail)&lt;br /&gt;VALUES (@MemberUserName, @MemberPassword, @MemberName, @MemberDOB, @NRIC, @MemberAddress,@MemberPhone, @MemberEmail)&lt;br /&gt;IF @@error &lt;&gt; 0&lt;br /&gt;RAISERROR('User was not added', 16, 1)&lt;br /&gt;ELSE&lt;br /&gt;BEGIN&lt;br /&gt;DECLARE @ID int&lt;br /&gt;SELECT @ID = @@IDENTITY&lt;br /&gt;SELECT Count(*)&lt;br /&gt;FROM Member1&lt;br /&gt;WHERE NRIC = @ID&lt;br /&gt;END&lt;br /&gt;END&lt;br /&gt;RETURN&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;These are the codings in my Visual Basic:&lt;br /&gt;Imports System.Web.Security 'Required Class for Authentication&lt;br /&gt;Imports System&lt;br /&gt;Imports System.Data 'DB Accessing Import&lt;br /&gt;Imports System.Data.DataSet&lt;br /&gt;Imports System.Data.SqlClient 'SQL Server Import&lt;br /&gt;Imports System.Configuration 'Required for Web.Config appSettings &lt;br /&gt;.................&lt;br /&gt;&lt;br /&gt;Public Class Registration&lt;br /&gt;Inherits System.Web.UI.Page&lt;br /&gt;&lt;br /&gt;Dim strConn As String = "Server=MyServer;Database=Cristwork ;Trusted_Connection=Yes"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Private Sub btn_submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_submit.Click&lt;br /&gt;If Page.IsValid Then ' ||||| Meaning the Control Validation was successful!&lt;br /&gt;' ||||| All fields have been filled in!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If ValidateNewUser(txtbox_user.Text.Trim(), txtbox_confirmpass.Text.Trim(), txtbox_name.Text.Trim(), txtbox_birthdate.Text.Trim(), txtbox_nric.Text.Trim(), txtbox_address.Text.Trim(), txtbox_contact.Text.TrimEnd(), txtbox_email.Text.TrimEnd()) Then&lt;br /&gt;AddNewUser(txtbox_user.Text.Trim(), txtbox_confirmpass.Text.Trim(), txtbox_name.Text.Trim(), txtbox_birthdate.Text.Trim(), txtbox_nric.Text.Trim(), txtbox_address.Text.Trim(), txtbox_contact.Text.TrimEnd(), txtbox_email.Text.TrimEnd())&lt;br /&gt;Response.Redirect("RegistrationSuccess.htm")&lt;br /&gt;&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Function ValidateNewUser(ByVal strUsername As String, ByVal strPassword As String, ByVal strName As String, ByVal strDOB As String, ByVal strNric As String, ByVal strAddress As String, ByVal strPhone As String, ByVal strEmail As String) As Boolean&lt;br /&gt;&lt;br /&gt;'&lt;summary&gt;&lt;br /&gt;'This function simply verifies that there is no existing match on&lt;br /&gt;'username (alias), and that the user has not already registered!&lt;br /&gt;' &lt;/sumary&gt;&lt;br /&gt;&lt;br /&gt;'Set up a Connection Object to the SQL DB&lt;br /&gt;&lt;br /&gt;'SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("strConn"))&lt;br /&gt;'Pass in the StoreProcedure or Command String, as well as the Connection object&lt;br /&gt;SqlConnection.Open()&lt;br /&gt;Dim MyCmd As New SqlCommand("sp_CheckForDuplicates", SqlConnection)&lt;br /&gt;'Set the Command Type (Stored Procedure, Text, etc)&lt;br /&gt;MyCmd.CommandType = CommandType.StoredProcedure&lt;br /&gt;'Create Parameter Objects for values passed in&lt;br /&gt;Dim objParam1, objParam2, objParam3, objParam4, objParam5, objParam6, objParam7, objParam8 As SqlParameter&lt;br /&gt;'Create a parameter to store your Return Value from the Stored Procedure&lt;br /&gt;&lt;br /&gt;Dim objReturnParam As SqlParameter&lt;br /&gt;'Add your parameters to the parameters Collection&lt;br /&gt;objParam1 = MyCmd.Parameters.Add(New SqlParameter("@MemberUserName", SqlDbType.VarChar, 254))&lt;br /&gt;'MyCmd.Parameters("@MemberUserName").Direction = ParameterDirection.Input&lt;br /&gt;'MyCmd.Parameters("@MemberUserName").Value = txtbox_user.Text&lt;br /&gt;objReturnParam = MyCmd.Parameters.Add("@Duplicates", SqlDbType.Int)&lt;br /&gt;objReturnParam.Direction = ParameterDirection.ReturnValue&lt;br /&gt;&lt;br /&gt;txtbox_user.Text = strUsername&lt;br /&gt;objParam1.Value = strUsername&lt;br /&gt;&lt;br /&gt;' ||||| Was the return value greater than 0 ???&lt;br /&gt;If objReturnParam.Value &gt; 0 Then&lt;br /&gt;lblstatus.Text = "UserName already exists or you are already a registered user!"&lt;br /&gt;Return False&lt;br /&gt;Else&lt;br /&gt;Return True&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;' ||||| Close the Connection Closes with it&lt;br /&gt;Try&lt;br /&gt;' ||||| Check if Connection to DB is already open, if not, then open a connection&lt;br /&gt;MyCmd.ExecuteNonQuery()&lt;br /&gt;If SqlConnection.State = ConnectionState.Open Then&lt;br /&gt;' ||||| DB not already Open...so open it&lt;br /&gt;SqlConnection.Close()&lt;br /&gt;&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;Catch ex As Exception&lt;br /&gt;lblError.Text = "Error Connecting to Database!"&lt;br /&gt;End Try&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;br /&gt;Function AddNewUser(ByVal strUsername As String, ByVal strPassword As String, ByVal strName As String, ByVal strDOB As String, ByVal strNric As String, ByVal strAddress As String, ByVal strPhone As String, ByVal strEmail As String) As Boolean&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;' ||||| Set up a Connection Object to the SQL DB&lt;br /&gt;'Dim SqlConnection As New SqlConnection(Convert.ToString(Application("strConn")))&lt;br /&gt;&lt;br /&gt;' ||||| Pass in the StoreProcedure or Command String, as well as the Connection object&lt;br /&gt;Dim MyCmd As New SqlCommand("sp_RegisterNewUser", SqlConnection)&lt;br /&gt;' ||||| Set the Command Type (Stored Procedure, Text, etc)&lt;br /&gt;MyCmd.CommandType = CommandType.StoredProcedure&lt;br /&gt;' ||||| Create Parameter Objects for values passed in&lt;br /&gt;Dim objParam1 As SqlParameter&lt;br /&gt;&lt;br /&gt;' ||||| Create a parameter to store your Return Value from the Stored Procedure&lt;br /&gt;Dim objReturnParam As SqlParameter&lt;br /&gt;' ||||| Add your parameters to the parameters Collection&lt;br /&gt;objParam1 = MyCmd.Parameters.Add(New SqlParameter("@MemberUserName", SqlDbType.VarChar, 254))&lt;br /&gt;'MyCmd.Parameters("@MemberUserName").Direction = ParameterDirection.Input&lt;br /&gt;'MyCmd.Parameters("@MemberUserName").Value = txtbox_user.Text&lt;br /&gt;&lt;br /&gt;txtbox_user.Text = strUsername&lt;br /&gt;objParam1.Value = strUsername&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Try&lt;br /&gt;' ||||| Check if Connection to DB is already open, if not, then open a connection&lt;br /&gt;' ||||| DB not already Open...so open it&lt;br /&gt;&lt;br /&gt;MyCmd.ExecuteNonQuery()&lt;br /&gt;&lt;br /&gt;' ||||| Close the Connection Closes with it&lt;br /&gt;SqlConnection.Close()&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Catch ex As Exception&lt;br /&gt;lblError.Text = "Error Connecting to Database!"&lt;br /&gt;End Try&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;End Class &lt;br /&gt;&lt;br /&gt;daniweb&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/659185728455111653-7049835207891444348?l=insertintodb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://insertintodb.blogspot.com/feeds/7049835207891444348/comments/default' title='Poskan Komentar'/><link rel='replies' type='text/html' href='http://insertintodb.blogspot.com/2009/01/i-am-facing-huge-problem.html#comment-form' title='0 Komentar'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/659185728455111653/posts/default/7049835207891444348'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/659185728455111653/posts/default/7049835207891444348'/><link rel='alternate' type='text/html' href='http://insertintodb.blogspot.com/2009/01/i-am-facing-huge-problem.html' title=''/><author><name>RiaQ</name><uri>http://www.blogger.com/profile/02219056924149750665</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
