Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting value from Binary field
Message
From
27/01/2014 12:45:30
 
 
To
27/01/2014 10:22:24
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
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:
01592452
Views:
39
>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?

I think you have to convert the byte array (loDataParameterSQLClient.Value) to hex ?
declare @Tmp table
(	Id int IDENTITY(1,1) NOT NULL,
	MD5 binary(16) not null
);

insert into @Tmp (MD5) values (0xB3C54EFB6C02017046905007293650B1);
insert into @Tmp (MD5) values (0xB3C54EFB6C02017046905007293650B2);

declare @MD5 Binary(16);
SET @MD5 = 0xB3C54EFB6C02017046905007293650B2;


select * from @Tmp where (MD5 = @MD5);
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform