定义表类型:
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";