如何将字符串数组传递给存储过程 [英] How do I pass string array to stored procedure

查看:78
本文介绍了如何将字符串数组传递给存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 -



我收到错误:



对象不存在映射键入System.String []到已知的托管提供程序本机类型。



我正在尝试将字符串数组传递给我的存储过程,但是如何。我正在查看网格抓取所选的ID,然后将这些ID传递给存储过程以查看它们是否有效。如果该ID无效,那么做一些事情,如果它做了其他事情。



以下是代码片段



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

        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

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

推荐答案

在存储过程中解析分隔的字符串 [ ^ ]



Y.您需要使用类似文章中描述的方法来解析存储过程中的数组并对结果执行操作。
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.


这篇关于如何将字符串数组传递给存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆