zoukankan      html  css  js  c++  java
  • sqlserver2008 中使用 表值 参数

    1.声明用户自定义表类型

    CREATE TYPE [dbo].[pmodelTable] AS TABLE(
        [pmodel] [varchar](60) NULL  --要传入的列
    )
    GO

    2.存储过程中使用自定义表类型

    create proc P_GetPmidByPmodel
    (
    @pmodel pmodelTable readonly --自定义的表类型
    )
    as
    begin
        select pmid from V_ProductModel v
        inner join @pmodel p on v.pmodel=p.pmodel
    end
    go

    3.测试效果

    declare @table as pmodelTable   
    --模拟几条数据
    insert into @table values('AUD1100')
    insert into @table values('AUDA100')
    insert into @table values('AUD8400')
    insert into @table values('AUD8450')
    exec P_GetPmidByPmodel @table

    4.asp.net中使用带有表值参数的存储过程

           #region 根据pmodel 获取pmid
            /// <summary>
            /// 根据pmodel 获取pmid
            /// </summary>
            /// <param name="dt"></param>
            /// <returns></returns>
            public DataSet GetPmidByPmodel(DataTable dt)
            {
                DataSet ds = new DataSet();
                using (SqlConnection connection = new SqlConnection(SqlHelper.connString))
                {
                    SqlCommand command = new SqlCommand();
                    command.Connection = connection;
                    command.CommandText = "P_GetPmidByPmodel";
                    command.CommandType = CommandType.StoredProcedure;
                    SqlParameter param = command.Parameters.AddWithValue("@pmodel", dt); //对应存储过程里的参数
                    param.SqlDbType = SqlDbType.Structured; //说明是特殊的数据类型
                    param.TypeName = "pmodelTable"; //自定义的表类型的名称
                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = command;
                    da.Fill(ds);
                }
                return ds;
            }
            #endregion
  • 相关阅读:
    20181022-JSP 开发环境搭建
    20181019-JSP 教程/简介
    20180829-Java多线程编程
    20180827(02)- Java发送邮件
    20180827-Java网络编程
    20180912-Java实例02
    docker安装redis
    springboot2集成swagger2出现guava包下的FluentIterable.append方法找不到
    Linux Centos7 网络设置UUID号的修改方法
    CentOS 7 主机名bogon解决办法
  • 原文地址:https://www.cnblogs.com/wugang/p/3054087.html
Copyright © 2011-2022 走看看