Private Function Save_Person() As String
' Open the connection
myCon.Open()
Dim myCmd As New SqlCommand("insert_New_Person", myCon)
myCmd.CommandType = CommandType.StoredProcedure
' Create a SqlParameter object to hold the output parameter value
Dim retValParam As New SqlParameter("@RETURN_VALUE", SqlDbType.Int)
' IMPORTANT - must set Direction as ReturnValue
retValParam.Direction = ParameterDirection.ReturnValue
' Add the parameters to the Command's Parameters collection
myCmd.Parameters.Add("@username", LCase(Username.Text))
myCmd.Parameters.Add("@password", NewPassword1.Text)
myCmd.Parameters.Add("@prefix", Prefix.Text)
myCmd.Parameters.Add("@firstname", CSQ(FName.Text)) ' CSQ = Comment Single Quotes
myCmd.Parameters.Add("@middlename", CSQ(MName.Text))
myCmd.Parameters.Add("@lastname", CSQ(LName.Text))
myCmd.Parameters.Add("@department", CSQ(Department.Text))
myCmd.Parameters.Add("@institution", CSQ(Institution.Text))
myCmd.Parameters.Add("@address1", CSQ(Address1.Text))
myCmd.Parameters.Add("@address2", CSQ(Address2.Text))
myCmd.Parameters.Add("@address3", CSQ(Address3.Text))
myCmd.Parameters.Add("@address4", CSQ(Address4.Text))
myCmd.Parameters.Add("@town", CSQ(City.Text))
myCmd.Parameters.Add("@county", CSQ(State.Text))
myCmd.Parameters.Add("@postcode", PostalCode.Text)
myCmd.Parameters.Add("@country", ddlCountry.SelectedValue)
myCmd.Parameters.Add("@telephone", Phone.Text)
myCmd.Parameters.Add("@fax", Fax.Text)
myCmd.Parameters.Add("@email", Email.Text)
' Finally, add the output parameter
myCmd.Parameters.Add(retValParam)
Dim dr As SqlDataReader
' Call the SProc...
Try
dr = myCmd.ExecuteReader()
' Now you can grab the output parameter's value...
Dim retVal As Integer = Convert.ToInt32(retValParam.Value)
If retVal > 0 Then
Save_Person = "OK"
Else
Save_Person = "Error"
End If
Catch ex As Exception
' Record any exceptions and exit
Dim myLiteral As New Literal
myLiteral.Text = "The following exception occurred: <br />" + ex.Message.ToString
Page.Controls.Add(myLiteral)
Save_Person = "Error"
End Try
dr.Close()
myCon.Close()
End Function