Anyone know what the VB.NET equivalent of this C# statement is...
byte [] segBody = (byte []) sqlReader.GetSqlBinary(3);
Tried as hard as I could to do it in VB.NET but I cannot seem to do it. 5 1910
Hi Gareth,
|| byte [] segBody = (byte []) sqlReader.GetSqlBinary(3);
GetSqlBinary returns a SqlBinary structure rather than an array of bytes,
so a straight conversion to VB fails, as you have found. Does that C#
statement actually work?
These fail:
Dim segBody1 As Byte() _
= DirectCast (sqlReader.GetSqlBinary(3), Byte()) 'Fails
Dim segBody2 As Byte() _
= CType (sqlReader.GetSqlBinary(3), Byte()) 'Fails
See if this code [untested] gives you some joy:
(Imports System.Data.SqlTypes)
Dim sqlBinValue As SqlBinary = sqlReader.GetSqlBinary(3)
Dim segBody As Byte() = SqlBinary.op_Explicit (sqlBinValue)
Regards,
Fergus
Thanks Fergus. Funnily enough the C# code works perfectly. I'll try your VB
example right now.
Cheers,
Gareth
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:OS**************@tk2msftngp13.phx.gbl... Hi Gareth,
|| byte [] segBody = (byte []) sqlReader.GetSqlBinary(3);
GetSqlBinary returns a SqlBinary structure rather than an array of
bytes, so a straight conversion to VB fails, as you have found. Does that C# statement actually work?
These fail: Dim segBody1 As Byte() _ = DirectCast (sqlReader.GetSqlBinary(3), Byte())
'Fails Dim segBody2 As Byte() _ = CType (sqlReader.GetSqlBinary(3), Byte()) 'Fails
See if this code [untested] gives you some joy: (Imports System.Data.SqlTypes) Dim sqlBinValue As SqlBinary = sqlReader.GetSqlBinary(3) Dim segBody As Byte() = SqlBinary.op_Explicit (sqlBinValue)
Regards, Fergus
Fergus. Excellant stuff that worked nicely!
"Gareth Parris" <gc******@hotmail.comm> wrote in message
news:uE**************@TK2MSFTNGP12.phx.gbl... Thanks Fergus. Funnily enough the C# code works perfectly. I'll try your
VB example right now.
Cheers, Gareth
"Fergus Cooney" <fi******@tesco.net> wrote in message news:OS**************@tk2msftngp13.phx.gbl... Hi Gareth,
|| byte [] segBody = (byte []) sqlReader.GetSqlBinary(3);
GetSqlBinary returns a SqlBinary structure rather than an array of bytes, so a straight conversion to VB fails, as you have found. Does that C# statement actually work?
These fail: Dim segBody1 As Byte() _ = DirectCast (sqlReader.GetSqlBinary(3), Byte()) 'Fails Dim segBody2 As Byte() _ = CType (sqlReader.GetSqlBinary(3), Byte()) 'Fails
See if this code [untested] gives you some joy: (Imports System.Data.SqlTypes) Dim sqlBinValue As SqlBinary = sqlReader.GetSqlBinary(3) Dim segBody As Byte() = SqlBinary.op_Explicit (sqlBinValue)
Regards, Fergus
Hi Gareth,
That op_ Explicit was niggling away in my mind and I've just remembered.
C# provides the ability to define explicit conversions which take place
when a variable is cast from one form to another. op_Explicit is the function
that allows other languages to access that convesion.
So
(byte []) sqlReader.GetSqlBinary(3);
and
SqlBinary.op_Explicit (sqlReader.GetSqlBinary(3));
are equivalent.
Regards,
Fergus
I was not aware of that. That makes more sense now.
Many thanks again,
Gareth
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:u%****************@TK2MSFTNGP09.phx.gbl... Hi Gareth,
That op_ Explicit was niggling away in my mind and I've just
remembered. C# provides the ability to define explicit conversions which take
place when a variable is cast from one form to another. op_Explicit is the
function that allows other languages to access that convesion.
So (byte []) sqlReader.GetSqlBinary(3); and SqlBinary.op_Explicit (sqlReader.GetSqlBinary(3)); are equivalent.
Regards, Fergus
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Thames |
last post by:
Hi,
I have to repost my question for help.
Yesterday I set up two DB UDB ESE V8.2 server on linux and windows
platform, respectively. Both servers have been connected without any
problems...
|
by: Chuck Grimsby |
last post by:
(Repost, due to lack of submissions...)
The Microsoft Access Product Group (the people who build Microsoft
Access) want your help!
One of the main things we're working on for the near future...
|
by: Marcus Jacobs |
last post by:
Dear Group
I have written a file conversion program that uses strtof to convert
text strings to floats. It works as I intended except for my error
messages. It is my understanding that strtof...
|
by: Gareth Parris |
last post by:
Anyone know what the VB.NET equivalent of this C# statement is...
byte segBody = (byte ) sqlReader.GetSqlBinary(3);
Tried as hard as I could to do it in VB.NET but I cannot seem to do it.
|
by: ASP .NET Newbie |
last post by:
I am trying to insert a new record into my database, and have it return a
uniqueidentifier as the "newcatid". I don't use integers as my "id"'s, but
rather uniqueidentifiers. Here's my Stored...
|
by: Rahul |
last post by:
Hi Everybody
I have some problem in my script. please help me. This is script file.
I have one *.inq file. I want run this script in XML files. But this
script errors shows . If u want i am...
|
by: Gregory Edigaroff |
last post by:
Hello, Everybody!
Ok, I urgently need the solution for a following task in C++. This is the task from programmers contest,
so I believe somebody have a solution for it.
I need either a full...
|
by: k1ckthem1dget |
last post by:
I need to display the unsorted list of names and display the sorted list of names.
My program is getting a bunch of errors though, and i dont know why.
I am getting the following errors.
28:...
|
by: k1ckthem1dget |
last post by:
I need to display the unsorted list of names and display the sorted list of names.
My program is getting a bunch of errors though, and i dont know why.
I am getting the following errors.
28:...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |