Vb.net Code To Display Image In Picturebox From Sql Server

Welcome. Please Login, Register, Or Activate! 
type your username and password to login
Date: November 24, 2009, 09:09 AM
431687 members and 298693 Topics
Latest Member: Fiath
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  Vb.net Code To Display Image In Picturebox From Sql Server
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Vb.net Code To Display Image In Picturebox From Sql Server  (Read 101 views)
salamsy (m)
Vb.net Code To Display Image In Picturebox From Sql Server
« on: October 21, 2009, 10:59 AM »

pls house,

i need a vb.net code to retreive image from sql server using vb.net.I want to display the image using picturebox.excerpt from my sql query;

mycmd = New SqlCommand("select picture from biodata where id='" & TextBox2.Text & "'")
i-Guru (m)
Re: Vb.net Code To Display Image In Picturebox From Sql Server
« #1 on: October 21, 2009, 01:28 PM »

Hey man, i like this language.
Can you pls do me a favor to tell me where you learnt it from.
Kobojunkie
Re: Vb.net Code To Display Image In Picturebox From Sql Server
« #2 on: October 21, 2009, 03:46 PM »

Well. . . .  you are sort of on the right track but you need to learn some basics on accessing databases and retrieving information @Poster. You also need to know how to access information contained in resultsets returned to you. May I suggest you spend at least 8 hours focusing on ADO.NET data retrieval? I mean we could try to write your code for you over the next couple of days. But I think you can get better information if you put your head into a good chapter on ADO.NET, DataReaders/DataSets, DataTables, DataRows, DataColumns, SqlCommand and related objects.
ABAboi
Re: Vb.net Code To Display Image In Picturebox From Sql Server
« #3 on: November 22, 2009, 11:03 PM »

Its actually a straight forward process. Follow the following steps. However the following codes basically scans your computer for .JPEG file extensions and adds them direct to your SQLSERVER. But ofcourse u can decide to import the image in a picture box control prior saving it in the database.
Create a table named "ImageData"Its attributess are

Name (varChar50)
Picture  (Image)
CreateDate(varChar20)--'NOT REALLY NECCESSARY

Now in your Form,
You will need  2 buttons named btnSave and BtnSearch, textbox (txtName)

For the clicked event of btnSearch, add these codes
Dim pictureLocation As String
        Dim a As New OpenFileDialog
        a.Filter = ("Image files| *.JPG")
        pictureLocation = a.FileName
       
            a.ShowDialog()
            Using conn As New System.Data.SqlClient.SqlConnection("Data Source=DENSMAN-PC\SQLEXPRESS;Initial Catalog=aba;Integrated Security=True") 'Insert your connection string here
                conn.Open()

                Using cmd As New SqlClient.SqlCommand("Insert Into ImageData(Name, CreateDate, Picture) Values (@Name, @CreateDate, @Picture)", conn)
                    cmd.Parameters.Add(New SqlClient.SqlParameter("@Name", SqlDbType.VarChar)).Value = txtName.Text
                    cmd.Parameters.Add(New SqlClient.SqlParameter("@CreateDate", SqlDbType.VarChar)).Value = DateTime.Today
                    cmd.Parameters.Add(New SqlClient.SqlParameter("@Picture", SqlDbType.Image)).Value = IO.File.ReadAllBytes(a.FileName)
                    cmd.ExecuteNonQuery()
                End Using


            End Using
       
When you are done with the following, i can tell u other ways to modify and optimise your programme, then i will give u the second part once u get this working. Cheers
 Pls Help Me Out!  Buyer For Online Transcript Application Portal  Code  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 


Sections: Autos/Cars (2) Jobs/Vacancies (2) (3) Career Talk Education General(2) Politics Romance Computers Phones Travel
Sports Fashion Health Religion Celebrities TV/Movies (2) Music/Radio (2) Books Webmasters Programming

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa. See also: Nairalist Classified Ads
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.