How to convert this code vb.net C#.net [Resolved]

Posted by Jayakumars under C# on 8/19/2016 | Points: 10 | Views : 398 | Status : [Member] [MVP] | Replies : 1
Hi

How to convert this code vb.net C#.net. I tried code conversion in Google error through any one convert and post here.

Dim data As DataTable
Dim lb() As Byte = data.Rows(0).Item("MemberImage")
Dim lstr As New System.IO.MemoryStream(lb)
Image1.Image = Image.FromStream(lstr)
Image1.SizeMode = PictureBoxSizeMode.StretchImage
lstr.Close()


Mark as Answer if its helpful to you


Responses

Posted by: Rajnilari2015 on: 8/19/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Let's do a line by line conversion

Line 1:

VB.Net:
Dim data As DataTable

C# :
DataTable data; OR DataTable data = new DataTable();


Line 2:
VB.Net:
Dim lb() As Byte = data.Rows(0).Item("MemberImage")

C#:
var lb = data.Rows[0].Item["MemberImage"];


Line 3:

VB.Net:
Dim lstr As New System.IO.MemoryStream(lb)

C#:
System.IO.MemoryStream lstr = new System.IO.MemoryStream(lb);


Line 4:
VB.Net:
Image1.Image = Image.FromStream(lstr)

C#:
Image1.Image = Image.FromStream(lstr);


Line 5:
VB.Net :
Image1.SizeMode = PictureBoxSizeMode.StretchImage

C# :
Image1.SizeMode = PictureBoxSizeMode.StretchImage;


Line 6:
VB.Net :
lstr.Close()

C# :
 lstr.Close();


The full program :

DataTable data = new DataTable();
var lb = data.Rows[0].Item["MemberImage"];
System.IO.MemoryStream lstr = new System.IO.MemoryStream(lb);
Image1.Image = Image.FromStream(lstr);
Image1.SizeMode = PictureBoxSizeMode.StretchImage;
lstr.Close();


- OR -

DataTable data = new DataTable();
var lb = data.Rows[0].Item["MemberImage"];
using(System.IO.MemoryStream lstr = new System.IO.MemoryStream(lb))
{
Image1.Image = Image.FromStream(lstr);
Image1.SizeMode = PictureBoxSizeMode.StretchImage
lstr.Close();
}


Hope this helps. Let us know in case you face any issue.

--
Thanks & Regards,
RNA Team

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response