Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting value from Binary field
Message
From
27/01/2014 10:22:24
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Getting value from Binary field
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01592445
Message ID:
01592445
Views:
48
When a SQL select command is executed, I always store the full SQL select command that was sent to SQL Server. This is useful for troubleshooting.

It usually goes like this:
            ' If we have some parameters
            While loEnumerator.MoveNext
                loDataParameter = loEnumerator.Current

                    loDataParameterSQLClient = loEnumerator.Current
                    lcValue = loDataParameterSQLClient.Value.ToString

                    ' Based on the type
                    Select Case loDataParameterSQLClient.SqlDbType.ToString

                        ' Integer, Binary
                        Case "Int", "Binary"

                            ' String
                        Case "VarChar"
                            lcValue = "'" + oApp.SQLServerGetValueForInsertionInScript(lcValue) + "'"

                            ' Datetime
                        Case "DateTime"
                            ldDate = loDataParameterSQLClient.Value
                            lcValue = "'" + ldDate.Year.ToString + "-" + _
                             ldDate.Month.ToString.PadLeft(2, "0") + "-" + _
                             ldDate.Day.ToString.PadLeft(2, "0") + " " + _
                             ldDate.Hour.ToString.PadLeft(2, "0") + ":" + _
                             ldDate.Minute.ToString.PadLeft(2, "0") + ":" + _
                             ldDate.Second.ToString.PadLeft(2, "0") + "'"

                            ' String
                        Case "NVarChar"
                            lcValue = "'" + oApp.SQLServerGetValueForInsertionInScript(lcValue) + "'"
And, this may returns something like this:

DECLARE @NoCompany Int
DECLARE @MD5 Binary(16)

SET @NoCompany=339
SET @MD5=System.Byte[]

SELECT CompanyFile.Numero,CompanyFile.Filename FROM CompanyFile (NOLOCK) WHERE CompanyFile.NoCompany=@NoCompany AND CompanyFile.MD5=@MD5

But, as you can see, when this is a Binary type, I do not get something like 0xB3C54EFB6C02017046905007293650B1. There is already a ToString at the top which works ok for an Integer as I do not have to do additional processing. But, for a Binary type, ToString would simply show the type. How can I obtain the 0xB3C54EFB6C02017046905007293650B1 here?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Reply
Map
View

Click here to load this message in the networking platform