You should be using SqlDbType.Structured
. .Udt
is not a table-valued parameter or table type, that's a CLR User-Defined Type IIRC. A TVP / table-valued parameter is an alias type not a user-defined type. You also don't need to tell it the .UdtTypeName
because, again, this has nothing to do with TVPs, and your code shouldn't be mentioning Udt
in any shape or form.
If your procedure looks like this:
CREATE PROCEDURE dbo.MyProcedure
@ListOfGUIDs dbo.ListOfGuids READONLY
AS
BEGIN
...
END
Then your C# code can be:
SqlCommand cmd = new SqlCommand("dbo.MyProcedure", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter tvparam = cmd.Parameters.AddWithValue("@ListOfGUIDs", ListOfIDs);
tvparam.SqlDbType = SqlDbType.Structured;
Or, if you just have a statement, like SELECT * FROM @ListOfGUIDs
then:
SqlCommand cmd = new SqlCommand("SELECT * FROM @ListOfGUIDs", conn);
cmd.CommandType = CommandType.Text;
SqlParameter tvparam = cmd.Parameters.AddWithValue("@ListOfGUIDs", ListOfIDs);
tvparam.SqlDbType = SqlDbType.Structured;