How to pass table value parameters to stored procedure from .net code

后端 未结 5 2142
难免孤独
难免孤独 2020-11-22 00:35

I have a SQL Server 2005 database. In a few procedures I have table parameters that I pass to a stored proc as an nvarchar (separated by commas) and internally

5条回答
  •  独厮守ぢ
    2020-11-22 00:46

    Generic

       public static DataTable ToTableValuedParameter(this IEnumerable list, Func selector)
        {
            var tbl = new DataTable();
            tbl.Columns.Add("Id", typeof(T));
    
            foreach (var item in list)
            {
                tbl.Rows.Add(selector.Invoke(item));
    
            }
    
            return tbl;
    
        }
    

提交回复
热议问题