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. 6 2755
"Gareth Parris" <gc******@hotmail.comm> schrieb 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.
Untested:
dim segbody as byte() = directcast(sqlReader.GetSqlBinary(3), byte())
--
Armin
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: Dancefire |
last post by:
Hi, everyone,
I'm trying to use std::codecvt<to do the encoding conversion. I am
using following code for encoding conversion between wchar_t string
and char string(MBCS). I am not sure am I...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
| |