本文介绍了不使用存储过程的表值参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎只能在网上找到需要使用存储过程的表值参数示例.我记得过去在没有存储过程的情况下这样做过.这可能吗?

It seems all I can find online are examples of table-valued parameters that require using a stored procedure. I recall doing this in the past without the stored procedure. Is that possible?

此代码不断抛出有关未指定类型的错误.

This code keeps throwing an error about the type not being specified.

SqlCommand cmd = new SqlCommand(@"
        UPDATE t1
        SET t1.ScheduledStartUTC = t2.ScheduledStartUTC
        FROM ScheduleTickets AS t1
            INNER JOIN @SetScheduledStart AS t2 ON t1.ScheduleId = t2.ScheduleId AND t1.PatchSessionId  = t2.PatchSessionId
    ", c);
cmd.Parameters.Add("@SetScheduledStart", SqlDbType.Structured).Value = SetScheduleTicketsDateDT;
cmd.ExecuteNonQuery();

推荐答案

在这里你可以找到如何在没有存储过程的情况下使用它:将表值参数传递给参数化SQL语句

Here you can find how to use it without stored procedure: Passing a Table-Valued Parameter to a Parameterized SQL Statement

基本上,它要求您:

  1. 事先在服务器上创建类型 dbo.tvpUpdateScheduledStart AS TABLE (ScheduleId int, PatchSessionId int).
  2. SqlParameterTypeName 属性中指定此类型.
  1. CREATE TYPE dbo.tvpUpdateScheduledStart AS TABLE (ScheduleId int, PatchSessionId int) on the server beforehand.
  2. Specify this type in TypeName property of a SqlParameter.

这篇关于不使用存储过程的表值参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-12 03:20