sql-variant

How can I set column type when using SqlBulkCopy to insert into a sql_variant column

南笙酒味 提交于 2019-12-10 19:18:09
问题 I'm using SqlBulkCopy to insert/update from a .net DataTable object to a SQL Server table that includes a sql_variant column. However SqlBulkCopy insists on storing DateTime values put into that column as sql type 'datetime' when what I need is 'datetime2'. My DataTable is defined like this: DataTable dataTable = new DataTable(); dataTable.Columns.Add(new DataColumn("VariantValue", typeof(object))); //this represents my sql_variant column Then I throw some data in there that requires a

Are there any benefits to using sql_variant over varchar in SQL Server?

浪子不回头ぞ 提交于 2019-12-05 12:49:06
问题 I currently have a database table setup as follows (EAV - business reasons are valid): Id - int (PK) Key - unique, varchar(15) Value - varchar(1000) This allows me to add in mixed values into my databse as key/value pairs. For example: 1 | 'Some Text' | 'Hello World' 2 | 'Some Number' | '123456' etc. In my C# code I use ADO.Net using reader.GetString(2); to retrieve the value as a string, then have my code elsewhere convert it as needed, for example... Int32.ParseInt(myObj.Value); . I'm

Are there any benefits to using sql_variant over varchar in SQL Server?

岁酱吖の 提交于 2019-12-03 23:58:17
I currently have a database table setup as follows (EAV - business reasons are valid): Id - int (PK) Key - unique, varchar(15) Value - varchar(1000) This allows me to add in mixed values into my databse as key/value pairs. For example: 1 | 'Some Text' | 'Hello World' 2 | 'Some Number' | '123456' etc. In my C# code I use ADO.Net using reader.GetString(2); to retrieve the value as a string, then have my code elsewhere convert it as needed, for example... Int32.ParseInt(myObj.Value); . I'm looking at enhancing my table by possibly changing the value column to a sql_variant datatype, but I don't

Passing parameter of type 'object' in table-valued parameter for sql_variant column

吃可爱长大的小学妹 提交于 2019-12-03 23:43:30
问题 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