Back to Browse

Get an image SQL Server database from DataGridView to PictureBox in VB.NET

16.7K views
Nov 14, 2013
1:00

VB.NET programming. In this tutorial I want to show you how to retrieve an image in DataGridView loaded from SQL Server to PictureBox in VB.NET. my codes: **Form Event:** Private con As New SqlConnection("YourConnectionString") Private com As SqlCommand Private Sub DGV_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV.CellClick con.Open() com = New SqlCommand("SELECT MyPhoto FROM tbGalary WHERE ID=" & DGV.Rows(e.RowIndex).Cells(0).Value, con) Dim ms As New MemoryStream(CType(com.ExecuteScalar, Byte())) txtPicture.Image = Image.FromStream(ms) txtPicture.SizeMode = PictureBoxSizeMode.StretchImage com.Dispose() con.Close() End Sub **SQL Table:** CREATE TABLE [dbo].[tbGalary]( [ID] [int] NOT NULL, [MyPhoto] [image] NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] **SQL Insert image:** INSERT INTO tbGalary VALUES('1','D:\image1.jpg') INSERT INTO tbGalary VALUES('2','D:\image2.jpg') INSERT INTO tbGalary VALUES('3','D:\image3.jpg') INSERT INTO tbGalary VALUES('4','D:\image4.jpg') INSERT INTO tbGalary VALUES('5','D:\image5.jpg')

Download

0 formats

No download links available.

Get an image SQL Server database from DataGridView to PictureBox in VB.NET | NatokHD