469,579 Members | 1,111 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

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 18 '05 #1
7 1543

"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 18 '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 18 '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 18 '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 18 '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 18 '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 18 '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 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Logan X via .NET 247 | last post: by
7 posts views Thread by patang | last post: by
6 posts views Thread by patang | last post: by
4 posts views Thread by Edwin Knoppert | last post: by
3 posts views Thread by mrajanikrishna | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.