Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi -

I'm getting the error:

"No mapping exists from object type System.String[] to a known managed provider native type."

I'm trying to pass a string array to my stored procedure but how. I'm looking through a grid grabbing the IDs that are selected then want to pass those to the stored procedure to see if they are valid. If that ID isnt valid then do something and if it is do something else.

Here are the code snippets

VB
        For Each row As DataGridItem In dgAssets.Items
            Dim c As Boolean = DirectCast(row.FindControl("cbSelect"), CheckBox).Checked
            If (c) Then
                ptsId = DirectCast(row.FindControl("txtPTSID"), Label).Text
                ptsIdList.Add(ptsId)
            End If
        Next
        Dim myPtsArr As String() = CType(ptsIdList.ToArray(GetType(String)), String())

        If (resultCheck.CheckFailStatus(myPtsArr) = "F") Then
Do Stuff
End If


Here is the method that calls the procedure
VB
Public Function CheckFailStatus(ptsId() As String) As String
        Dim result As String
        Dim cs As String = ConfigurationManager.ConnectionStrings("PTS_EConnectionStringDEV").ConnectionString
        Using con As New SqlConnection(cs)
            Dim cmd As New SqlCommand("stpr_CheckFailStatus", con)
            cmd.CommandType = CommandType.StoredProcedure
            Dim parm As New SqlParameter("@PTSID", ptsId)
            cmd.Parameters.Add(parm)
            con.Open()
            Dim reader As SqlDataReader = cmd.ExecuteReader()
            While reader.Read()
                result = (reader("RESV_STATUS").ToString())
            End While
Posted
Updated 9-Oct-15 10:49am
v3

1 solution

Parse delimited string in a Stored procedure [^]

You'll need to use something like the method described in the article to parse out the array inside the stored procedure and perform an action on the result.
 
Share this answer
 
v2
Comments
Troy Bryant 12-Oct-15 15:38pm    
I believe doing that worked although now my error is "No mapping exists from object type System.String[] to a known managed provider native type"
R. Giskard Reventlov 12-Oct-15 15:42pm    
Are you passing the data as string or string[]? It should just be a delimited string.
Troy Bryant 12-Oct-15 16:16pm    
passing it as the string[] how else would I convert that from the code above?
R. Giskard Reventlov 12-Oct-15 16:22pm    
It needs to be passed as a comma delimited string, not an array. The stored proc then takes care of the pseudo array you have passed. So, don't add each item to the array, add it to simple string with a comma after each value then pass that string to the stored proc and it will work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900