I have a table-valued parameter in SQL Server 2012 defined as:
CREATE TYPE [dbo].[TVP] AS TABLE (
[Id] [int] NOT NULL,
[FieldName] [nvarchar](100) NOT NULL,
[Value] [sql_variant] NOT NULL
)
I call it in C# with code that looks roughly like the following:
var mdItems = new DataTable();
mdItems.Columns.Add("Id", typeof(int));
mdItems.Columns.Add("FieldName", typeof(string));
mdItems.Columns.Add("Value", typeof(object));
mdItems.Rows.Add(new object[] {2, "blah", "value"}); //'value' is usually a string
SqlCommand sqlCommand = conn.CreateCommand();
sqlCommand.CommandText = "[WriteFieldValues]";
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.Parameters.AddWithValue("@FieldValues", mdItems);
sqlCommand.ExecuteNonQuery();
I then get the following error from SQL Server on the ExecuteNonQuery
call:
The type of column 'Value' is not supported. The type is 'Object'
I found someone who encountered the same problem 3 years ago when it was identified as a known Microsoft bug. The link to the bug is broken, though. Does anyone know if there is updated information on the status of the bug or a potential workaround? As it stands, this bug really kills the value of sql_variant
fields.
sql_variant
? Just curious. – Shortage