C# Sql Server 数据库 传递 表值参数

定义表类型:

CREATE TYPE [dbo].[QuestionList] AS TABLE(
    [QuestionGroupCode] [nvarchar](26) NULL,
    [StudentCode] [nvarchar](50) NULL,
    [MajorQuestionID] [int] NULL,
    [MinorQuestionID] [int] NULL
)

定义存储过程,表类型作为参数:

CREATE PROCEDURE [dbo].[spIsQuestionValid]
    @Question AS QuestionList READONLY
AS
BEGIN
  ...
END

C#调用:

var dt = new DataTable();
dt.Columns.Add("QuestionGroupCode", typeof(string));
dt.Columns.Add("StudentCode", typeof(string));
dt.Columns.Add("MajorQuestionID", typeof(int));
dt.Columns.Add("MinorQuestionID", typeof(int));
var p = new SqlParameter("@Question", SqlDbType.Structured);
p.Value = dt;
p.TypeName = "QuestionList";

 

C# Sql Server 数据库 传递 表值参数

上一篇:LevelDB的错误处理和Status类


下一篇:mysql5.7 报错Got an error reading communication packets 关于Aborted connection告警日志的分析