Problem with sql parameters when using FillByStoredProcedure


Author
Message
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Yeah....looks like you found your answer Smile  Sorry for the missed post.
Peter Jones
Peter Jones
Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi Guys,

No worries with this - my mate Pete has put me right. Simple really, declare the para within the If and get a new one for each iteration:

        For i As Integer = 0 To BOs.Count - 1
            If BOs.Item(i).InsertStoredProcedureName.ToString.Length >= 1 Then

                 Dim ProcParam As System.Data.SqlClient.SqlParameter
                 ProcParam = New System.Data.SqlClient.SqlParameter
                 With ProcParam
                    .ParameterName = "@Active"
                    .DbType = Data.DbType.Int32
                    .Direction = Data.ParameterDirection.Input
                    .Value = 1
                End With
                BOs.Item(i).FillByStoredProcedure(BOs.Item(i).InsertStoredProcedureName.ToString, ProcParam)
            End If
        Next

Cheers, Peter

Peter Jones
Peter Jones
Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi Guys,

You may have missed this post and one from Chan on the same day - no response as yet.

Cheers, Peter

Peter Jones
Peter Jones
Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi,

We have the following code which refreshes all combo boxes on a form (DevExpress BTW) when the form goes into add new record mode. It makes sure the user only sees records in combo boxes that are currently 'active'.

When the code executes it throws the exception: {"The SqlParameter is already contained by another SqlParameterCollection."} in the .FillByStoredProcedure call. In researching this problem it seems as though the problem pops up a fair bit with the most common solution being to execute a cmd.Parameters.Clear() or something similar after the proc executes.

Apparently the error means exactly what it says however, in my case, I'm not so sure. I've rebooted both the data server backend and my workstation but it remains - I would have thought it would execute once then not again until the form was closed and reopened. However, it has worked at least once (maybe only once - I'm not sure now) but right now it errors every time the code is run, i.e. even after a reboot.

Obviously taking the "cmd.Parameters.Clear()" approach would mean doing something in the StrataFrame sources which we are not about to do so, any comments or suggestions on how to get around this problem would be appreciated.

Cheers, Peter

>>>>>>>>>>>>>>>>>>>>>>>>

    Public Shared Sub RefreshCombosForNewRow(ByVal BOs As MicroFour.StrataFrame.Business.BusinessObjectCollection)

        ' Right now we are just starting a new row so we want to make sure any lookup stored procs
        ' are refreshed using a parameter to only select active records.

        Dim ProcParam As System.Data.SqlClient.SqlParameter
        ProcParam = New System.Data.SqlClient.SqlParameter
        With ProcParam
            .ParameterName = "@Active"
            .DbType = Data.DbType.Int32
            .Direction = Data.ParameterDirection.Input
            .Value = 1
        End With

        ' Cycle through all BO's on the form. If they have insert proc name then the BO is for lookups and
        ' we need to refresh the combo box with just active records.
        For i As Integer = 0 To BOs.Count - 1
            If BOs.Item(i).InsertStoredProcedureName.ToString.Length >= 1 Then
                BOs.Item(i).FillByStoredProcedure(BOs.Item(i).InsertStoredProcedureName.ToString, ProcParam)
            End If
        Next
    End Sub
>>>>>>>>>>>>>>>>>>>>>>>>>>>>

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search