473,320 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can you convert this from C# to VB?

Hi, I'm trying to convert his line from C# to VB:

System.Drawing.Image _img=
System.Drawing.Image.FromStream(new
System.IO.MemoryStream((byte[])SqlReader["Image"]);

I have this so far:
dim Img as SystemDrawing.Image
Img=System.Drawing.Image.FromStream(new
System.IO.MemoryStream(Convert.ToByte(SqlReader("I mage"))))

I'm getting the error "specified cast is not valid". Basically, this line
reads in an image stored in a SQL server. My c# knowledge is lacking.....

Thanks. -Rob T.
Nov 20 '05 #1
7 2164

"Rob T" <RT*********@DONTwalchemSPAM.com> wrote in message
news:u1**************@tk2msftngp13.phx.gbl...
Hi, I'm trying to convert his line from C# to VB:

System.Drawing.Image _img=
System.Drawing.Image.FromStream(new
System.IO.MemoryStream((byte[])SqlReader["Image"]);

I have this so far:
dim Img as SystemDrawing.Image
Img=System.Drawing.Image.FromStream(new
System.IO.MemoryStream(Convert.ToByte(SqlReader("I mage"))))

I'm getting the error "specified cast is not valid". Basically, this line reads in an image stored in a SQL server. My c# knowledge is lacking.....


Looks to me like you're casting an Image to a Byte (not an Array of Bytes as
you intend)

Is there a .ToArray() method?

Brian Lowe
---------@
Nov 20 '05 #2
Try this:

Dim Img as SystemDrawing.Image
Img=System.Drawing.Image.FromStream(new
System.IO.MemoryStream(CType(SqlReader("Image"), Byte()))

/claes
"Rob T" <RT*********@DONTwalchemSPAM.com> wrote in message
news:u1**************@tk2msftngp13.phx.gbl...
Hi, I'm trying to convert his line from C# to VB:

System.Drawing.Image _img=
System.Drawing.Image.FromStream(new
System.IO.MemoryStream((byte[])SqlReader["Image"]);

I have this so far:
dim Img as SystemDrawing.Image
Img=System.Drawing.Image.FromStream(new
System.IO.MemoryStream(Convert.ToByte(SqlReader("I mage"))))

I'm getting the error "specified cast is not valid". Basically, this line reads in an image stored in a SQL server. My c# knowledge is lacking.....

Thanks. -Rob T.

Nov 20 '05 #3
You need to make a byte array, not a byte, so ConvertToByte() will not work
here. I would use CType(readerNameHere, Byte()).

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"Rob T" <RT*********@DONTwalchemSPAM.com> wrote in message
news:u1**************@tk2msftngp13.phx.gbl...
Hi, I'm trying to convert his line from C# to VB:

System.Drawing.Image _img=
System.Drawing.Image.FromStream(new
System.IO.MemoryStream((byte[])SqlReader["Image"]);

I have this so far:
dim Img as SystemDrawing.Image
Img=System.Drawing.Image.FromStream(new
System.IO.MemoryStream(Convert.ToByte(SqlReader("I mage"))))

I'm getting the error "specified cast is not valid". Basically, this line reads in an image stored in a SQL server. My c# knowledge is lacking.....

Thanks. -Rob T.

Nov 20 '05 #4
Ah....the array is what did me in.

This is what I did to get it work:

Dim AryByte() as Byte

AryByte = SqlReader("Image")

Img=System.Drawing.Image.FromStream(new

System.IO.MemoryStream(AryByte)

Thanks for your help!

"Rob T" <RT*********@DONTwalchemSPAM.com> wrote in message
news:u1**************@tk2msftngp13.phx.gbl...
Hi, I'm trying to convert his line from C# to VB:

System.Drawing.Image _img=
System.Drawing.Image.FromStream(new
System.IO.MemoryStream((byte[])SqlReader["Image"]);

I have this so far:
dim Img as SystemDrawing.Image
Img=System.Drawing.Image.FromStream(new
System.IO.MemoryStream(Convert.ToByte(SqlReader("I mage"))))

I'm getting the error "specified cast is not valid". Basically, this line reads in an image stored in a SQL server. My c# knowledge is lacking.....

Thanks. -Rob T.

Nov 20 '05 #5
Better yet, use an online C# to VB converter, or download the exe and
convert more code at once.

http://www.kamalpatel.net/ConvertCSharp2VB.aspx

"Rob T" <RT*********@DONTwalchemSPAM.com> schreef in bericht
news:u1**************@tk2msftngp13.phx.gbl...
Hi, I'm trying to convert his line from C# to VB:

System.Drawing.Image _img=
System.Drawing.Image.FromStream(new
System.IO.MemoryStream((byte[])SqlReader["Image"]);

I have this so far:
dim Img as SystemDrawing.Image
Img=System.Drawing.Image.FromStream(new
System.IO.MemoryStream(Convert.ToByte(SqlReader("I mage"))))

I'm getting the error "specified cast is not valid". Basically, this line reads in an image stored in a SQL server. My c# knowledge is lacking.....

Thanks. -Rob T.

Nov 20 '05 #6
Hi Richard,

No converting gives extra errors the line from Claes was already fine in my
opinion, I did want to send a message when I saw it.

Cor
Better yet, use an online C# to VB converter, or download the exe and
convert more code at once.

Nov 20 '05 #7
* "Richard" <ri*****@nospam.com> scripsit:
Better yet, use an online C# to VB converter, or download the exe and
convert more code at once.

http://www.kamalpatel.net/ConvertCSharp2VB.aspx


.... and a few more:

C# -> VB.NET Converters:

<URL:http://www.aspalliance.com/aldotnet/examples/translate.aspx>
<URL:http://www.kamalpatel.net/ConvertCSharp2VB.aspx>
<URL:http://csharpconverter.claritycon.com/>
<URL:http://www.ragingsmurf.com/vbcsharpconverter.aspx>
<URL:http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=c622348b-18a9-47d6-8687-979975d5957d>

<URL:http://www.remotesoft.com/>
-> "Octopus"

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Logan X via .NET 247 | last post by:
It's official....Convert blows. I ran a number of tests converting a double to an integer usingboth Convert & CType. I *ASSUMED* that CType would piggy-back ontop of Convert, and that performance...
4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
5
by: Cally | last post by:
Hello, I would like to convert a field from ntext field found in one database table to float field found in another database table. The reason why I want to do this is a long one. I have...
7
by: whatluo | last post by:
Hi, all I'm now working on a program which will convert dec number to hex and oct and bin respectively, I've checked the clc but with no luck, so can anybody give me a hit how to make this done...
6
by: MrKrich | last post by:
I want to convert Hexadecimal or normal integer to Binary. Does VB.Net has function to do that? I only found Hex function that convert normal integer to Hexadecimal.
7
by: patang | last post by:
I want to convert amount to words. Is there any funciton available? Example: $230.30 Two Hundred Thirty Dollars and 30/100
6
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function...
4
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot. This way i can assure the text is correct. However...
3
by: mrajanikrishna | last post by:
Hi Friends, I am accepting a number from the user entered in a textbox. I want to assign to a variable in my code and assignt this to that variable. double num1 = (double)txtNum1.text; ...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.