Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8461741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:57:38+00:00 2026-06-10T13:57:38+00:00

The stored procedure ins_address works if used stand-alone, no errors. When using the VB

  • 0

The stored procedure ins_address works if used stand-alone, no errors.
When using the VB code (shown below), a row does not get inserted into tbl_AddressEntity. tbl_Address does, it’s fine. I have racked my brains for nearly two whole days and I’m ready to jump off a cliff. Can anyone advise why the row won’t insert into the second table? Thank you.

`

ALTER PROCEDURE [dbo].[ins_address]
@AddressLine1 AS VARCHAR(60),
@AddressLine2 AS VARCHAR(60),
@AddressLine3 AS VARCHAR(60),
@TownText AS VARCHAR(30),
@CountyText AS VARCHAR(30),
@PostcodeTownDistrictID AS INT,
@PostcodeOutwardCode AS VARCHAR(4),
@PostcodeInwardCode AS VARCHAR(3),
@SiteID AS INT,
@CompanyBranchID AS INT,
@PersonID AS INT,
@AddressTypeID AS INT,
@AddressID AS INT = -1 OUTPUT

AS 

BEGIN TRY
INSERT INTO tbl_Address 
(
AddressLine1, 
AddressLine2, 
AddressLine3, 
TownText, 
CountyText,
PostcodeTownDistrictID,
PostcodeOutwardCode,
PostcodeInwardCode
)
VALUES 
(
@AddressLine1, 
@AddressLine2, 
@AddressLine3, 
@TownText, 
@CountyText,
@PostcodeTownDistrictID,
@PostcodeOutwardCode,
@PostcodeInwardCode
);

RETURN SCOPE_IDENTITY();

SELECT @AddressID = SCOPE_IDENTITY();

INSERT INTO tbl_AddressEntity
(
AddressID,
SiteID,
CompanyBranchID,
PersonID,
AddressTypeID
)
VALUES
(
@AddressID,
@SiteID,
@CompanyBranchID,
@PersonID,
@AddressTypeID
);

END TRY

BEGIN CATCH
 DECLARE
        @ErrorMessage nvarchar(2048)
        ,@ErrorSeverity int
        ,@ErrorState int

    SELECT
        @ErrorMessage = ERROR_MESSAGE()
        ,@ErrorSeverity = ERROR_SEVERITY()
        ,@ErrorState = ERROR_STATE();

IF @@TRANCOUNT > 0

    RAISERROR(@ErrorMessage, @ErrorSeverity, @ErrorState);

END CATCH

`


`

Private Sub UBSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UBSave.Click
          Try

                    If Not formOptions(0).Contains("Company Customer") Then
                        'Force commit of data changes to DS
                        **Me.UGAddresses.UpdateData()**
                        Me.UGContactInformation.UpdateData()

                        'Merge text boxes into DS
                        getNonCompanyCustomerFields()

                        'Save the contact first!
                        kernel.updateContact(Me.DsContact1)

                        'Now assuming we have the PKID from the contact insert, update associations to match!
                        If formOptions(0).Contains("New") Then
                            For Each row As DataRow In DsAddress1.Tables(0).Rows
                                If row.RowState = DataRowState.Added Then
                                    If row.Item("PersonID") Is System.DBNull.Value Then
                                        row.Item("PersonID") = DsContact1.Tables(0).Rows(0).Item("PersonID")
                                    End If
                                End If
                            Next
                            For Each row As DataRow In DsContactInfo1.Tables(0).Rows
                                If row.RowState = DataRowState.Added Then
                                    If row.Item("PersonID") Is System.DBNull.Value Then
                                        row.Item("PersonID") = DsContact1.Tables(0).Rows(0).Item("PersonID")
                                    End If
                                End If
                            Next
                            If Me.UTCMain.Tabs("Customer").Visible Then
                                Me.DsCustomers1.Tables(0).Rows(0).Item("PersonID") = DsContact1.Tables(0).Rows(0).Item("PersonID")
                            End If
                        End If

                        **kernel.updateAddresses(Me.DsAddress1)**
                        kernel.updateContactInfo(Me.DsContactInfo1)
                        If Me.UTCMain.Tabs("PersonCustomer").Visible Then
                            kernel.updateCustomer(Me.DsCustomers1)
                        End If
                        Me.Text = Me.Text.Replace(" *", "")

                        'Company Customer
                    Else
                        getCompanyCustomerFields()
                        kernel.updateCustomer(Me.DsCustomers1)
                        Me.Text = Me.Text.Replace(" *", "")
                    End If
                Catch ex As Exception
                    MsgBox("Exception thrown during save : " & ex.Message, MsgBoxStyle.Exclamation)
                    mySharedFunctions.LogProgress("frmContact.UBSave_Click - Error : " & ex.Message & vbCrLf & ex.StackTrace)
                    If Not ex.InnerException Is Nothing Then
                        mySharedFunctions.LogProgress("Inner exception : " & ex.InnerException.Message)
                    End If
                End Try
        End Sub

`


The data adapter update procedure:
`

Public Sub updateAddresses(ByRef dsTemp As dsAddress)

            'For inserts we're passing back the new PKID amd syncing with the dataset via the source column mapping on the insert command. 
            'So we should be able to update by ref.
            Me.SqlDaAddress.Update(dsTemp)
        End Sub

`


DsAddress1 dataset contains one table, containing results from this select statement in the relevant stored procedure:
`

ALTER PROCEDURE [dbo].[get_address_by_companybranch_or_person]
/*@SiteID AS INT = -1,*/
@CompanyBranchID AS INT = -1,
@PersonID AS INT = -1

AS

IF @CompanyBranchID != -1
BEGIN

    SELECT     dbo.tbl_Address.AddressID, dbo.tbl_Address.AddressLine1, dbo.tbl_Address.AddressLine2, dbo.tbl_Address.AddressLine3, 
                      dbo.tbl_Address.TownText, dbo.tbl_Address.CountyText, dbo.tbl_Address.PostcodeTownDistrictID, dbo.tbl_Address.PostcodeOutwardCode, 
                      dbo.tbl_Address.PostcodeInwardCode, dbo.tbl_AddressEntity.SiteID, dbo.tbl_AddressEntity.CompanyBranchID, dbo.tbl_AddressEntity.PersonID, 
                      dbo.tbl_AddressEntity.AddressTypeID
    FROM         dbo.tbl_Address INNER JOIN
                      dbo.tbl_AddressEntity ON dbo.tbl_Address.AddressID = dbo.tbl_AddressEntity.AddressID
    WHERE     CompanyBranchID = @CompanyBranchID

END
ELSE

BEGIN

    SELECT     dbo.tbl_Address.AddressID, dbo.tbl_Address.AddressLine1, dbo.tbl_Address.AddressLine2, dbo.tbl_Address.AddressLine3, 
                      dbo.tbl_Address.TownText, dbo.tbl_Address.CountyText, dbo.tbl_Address.PostcodeTownDistrictID, dbo.tbl_Address.PostcodeOutwardCode, 
                      dbo.tbl_Address.PostcodeInwardCode, dbo.tbl_AddressEntity.SiteID, dbo.tbl_AddressEntity.CompanyBranchID, dbo.tbl_AddressEntity.PersonID, 
                      dbo.tbl_AddressEntity.AddressTypeID
    FROM         dbo.tbl_Address INNER JOIN
                      dbo.tbl_AddressEntity ON dbo.tbl_Address.AddressID = dbo.tbl_AddressEntity.AddressID 
    WHERE   PersonID = @PersonID


END

`

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:57:40+00:00Added an answer on June 10, 2026 at 1:57 pm

    Why this line?

    RETURN SCOPE_IDENTITY(); 
    

    You exit from your stored proc at this point without executing the remaining code.

    MSDN says

    Exits unconditionally from a query or procedure. RETURN is immediate and complete 
    and can be used at any point to exit from a procedure, batch, or statement block. 
    Statements that follow RETURN are not executed. 
    

    … and please, don’t jump …. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This stored procedure does not save the data, it seems to be a problem
my stored procedure is like below, select T.TranNo,(Select Accountname from Accountable where AccountCode =T.tranAccountCode)
I've created my stored procedure, I've created the complex type using the entity model.
--Stored procedure ALTER PROCEDURE [dbo].[Test] @USERID varchar(25) AS BEGIN SET NOCOUNT ON IF NOT
My stored procedure looks like: WITH MYCTE(....) AS ( ... ) UPDATE ... (using
Stored procedure IF statement is not working @manuel varchar(50), @tour int, @tourname varchar(50) OUTPUT
I've a stored procedure that does something like this: SELECT Id INTO #temp FROM
My stored procedure is called as below from an SQL instegartion package within SQL
My stored procedure is not finishing today like it was yesterday. It still says
My stored procedure has the following code: WHERE tag IN (@InValue) I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.