I have the requirement to insert records into a SQL table that contains varbinary and image columns.
How do I get 0x00120A011EFD89F94DDA363BA64F57441DE9 (This is the same for all records)
into this
BLOB_TYPE (MY_UDDT(varbinary(18))?
This is what I have so far, everything being very straightforward except for the SqlDbType.Udt parameter definition. With this code I'm getting the error, "Specified type is not registered on the target server.System.Byte[]", I can say 100% the 'User-Defined Data Type' exists on the server. I queried select * from sys.types and it returned the type.
Definition: CREATE TYPE [dbo].[MY_UDDT] FROM varbinary NOT NULL
sql = "INSERT INTO dbo.BLOBS (BLOB_TYPE) VALUES (@BLOB_TYPE);"
cmd = New SqlCommand(sql, conn)
Dim parameter As New SqlParameter("@BLOB_TYPE", SqlDbType.Udt)
With parameter
.SqlDbType = SqlDbType.Udt
.UdtTypeName = "dbo.MY_UDDT"
.Value = blobType
End With
cmd.Parameters.Add(parameter)
cmd.ExecuteNonQuery()
Public ReadOnly Property blobType As Byte()
Get
Dim Str As String = "0x00620A011EFD89F94DDA863BA64F57441DE9"
Dim bytes As Byte() = New Byte(Str.Length * 2 - 1) {}
System.Buffer.BlockCopy(Str.ToCharArray(), 0, bytes, 0, bytes.Length)
Return bytes
End Get
End Property