Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用存储过程将VB.net插入到多个相关表中。只有第一个表接收插入的行_Vb.net_Visual Studio 2008_Stored Procedures_Sqldataadapter_Insert Into - Fatal编程技术网

使用存储过程将VB.net插入到多个相关表中。只有第一个表接收插入的行

使用存储过程将VB.net插入到多个相关表中。只有第一个表接收插入的行,vb.net,visual-studio-2008,stored-procedures,sqldataadapter,insert-into,Vb.net,Visual Studio 2008,Stored Procedures,Sqldataadapter,Insert Into,如果单独使用,则存储过程ins_地址可以工作,没有错误。 使用VB代码(如下所示)时,不会将行插入tbl_AddressEntity。tbl_地址有,没关系。我绞尽脑汁想了将近整整两天,准备跳下悬崖。有人能告诉我为什么行不能插入到第二个表中吗?多谢各位 ` ` ` 数据适配器更新过程: ` ` DsAddress1数据集包含一个表,其中包含相关存储过程中此select语句的结果: ` `为什么要写这行 RETURN SCOPE_IDENTITY(); 此时,您将退出存储过程,而不执行其

如果单独使用,则存储过程ins_地址可以工作,没有错误。 使用VB代码(如下所示)时,不会将行插入tbl_AddressEntity。tbl_地址有,没关系。我绞尽脑汁想了将近整整两天,准备跳下悬崖。有人能告诉我为什么行不能插入到第二个表中吗?多谢各位

`

`


`


数据适配器更新过程: `

`


DsAddress1数据集包含一个表,其中包含相关存储过程中此select语句的结果: `

`为什么要写这行

RETURN SCOPE_IDENTITY(); 
此时,您将退出存储过程,而不执行其余代码


。。。请不要跳…-)

啊!我不知道!我从其他人那里接管了数据库,不得不调整许多存储过程和代码。谢谢你的帮助。我想这就解释了为什么tbl_AddressEntity没有收到行!:-)很高兴能帮上忙。如果我的回答帮助您解决了问题,请花点时间阅读常见问题解答
`

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
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
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
RETURN SCOPE_IDENTITY(); 
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.