473,382 Members | 1,336 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,382 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 18 '05 #1
7 1657

"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 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...
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...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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 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.