while using table valued parameter how to pass multiple parameter together to stored prcocedure

前端 未结 3 1094
Happy的楠姐
Happy的楠姐 2021-01-23 22:15

I have a table-valued parameter like this

CREATE TYPE dbo.Loc AS TABLE(Lo integer);

My stored procedure looks like this:

ALTER PROCEDURE [dbo].[T         


        
3条回答
  •  孤街浪徒
    2021-01-23 22:39

    cnt = LSTlocations.SelectedItems.Count
    ' *** Set up the DataTable here: *** '
    Dim locTable As New DataTable
    locTable.Columns.Add("Lo", GetType(Integer))
    
    If cnt > 0 Then
        For i = 0 To cnt - 1
            Dim locationanme As String = LSTlocations.SelectedItems(i).ToString
            locid = RecordID("Locid", "Location_tbl", "LocName", locationanme)
            ' *** Add the ID to the table here: *** '
            locTable.Rows.Add(locid)
        next
    end if  
    
    Dim da As New SqlDataAdapter
    Dim ds As New DataSet
    Dim cmd23 As New SqlCommand("IBS_TransactionSummary", con.connect)
    cmd23.CommandType = CommandType.StoredProcedure
    cmd23.Parameters.Add("@startDate", SqlDbType.NVarChar, 50, ParameterDirection.Input).Value = startdate
    cmd23.Parameters.Add("@endDate", SqlDbType.NVarChar, 50, ParameterDirection.Input).Value = enddate
    ' *** Supply the DataTable as a parameter to the procedure here: *** '
    Dim tvp1 As SqlParameter =cmd23.Parameters.AddWithValue("@location", locTable)
    tvp1.SqlDbType = SqlDbType.Structured
    tvp1.TypeName = "dbo.Loc"
    da.SelectCommand = cmd23
    da.Fill(ds)
    

提交回复
热议问题