473,396 Members | 1,872 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,396 software developers and data experts.

Image Column in Windows Application

Hi,
Iam working on windows based application.In that i dont know how to add image in grid view column. I want to add image column in grid view.Image path will be stored in Ms-Access database.I want to retrieve path from database and place image in gridview column.

Please help me.

Thanks & Regards
Neeraja.
Oct 20 '08 #1
1 1318
Prathap
37
Here i've used picturebox.
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlClient
  2. Imports System.Data
  3. Imports System.IO
  4.  
  5.  Public Class Form1
  6.     Dim str As String = "Data Source=NET3\SQLEXPRESS;Initial Catalog=RestPos;Persist Security Info=True;User ID=sa;Password=password"
  7.     Dim con As New SqlClient.SqlConnection
  8.  
  9.     'To open an image from computer
  10.     '-------------------------------
  11.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  12.         OpenFileDialog1.Title = "Please select a file"
  13.         OpenFileDialog1.InitialDirectory = "c:temp"
  14.         OpenFileDialog1.ShowDialog()
  15.         TextBox2.Text = OpenFileDialog1.FileName.ToString  '--->To Show the file path in textbox2
  16.         PictureBox1.ImageLocation = TextBox2.Text  '--->To show selected image in picturebox
  17.     End sub
  18.  
  19.    'To insert selected image into database
  20.    'The datatype of the column in table to store image should be <image>  
  21.    '--------------------------------------------------------------------
  22.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  23.         con.ConnectionString = str
  24.         Dim ms As New IO.MemoryStream()
  25.         PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
  26.         Dim arrimage() As Byte = ms.GetBuffer
  27.         Dim cmd As New SqlCommand("insert into image (Emp_Image)values(@picture)", con)
  28.         cmd.Parameters.Add(New SqlParameter("@Picture", SqlDbType.Image)).Value = arrimage
  29.         con.Open()
  30.         cmd.ExecuteNonQuery()
  31.         con.Close()
  32.     End Sub
  33.  
  34.     'We have successfully inserted the image into database.
  35.     'Now we want to Retrieve the image from database.
  36.     '-------------------------------------------------
  37.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  38.         Dim stream As New IO.MemoryStream()
  39.         con.Open()
  40.         Dim command As New SqlCommand("select Emp_Image from Image where Emp_Id='" + TextBox3.Text + "'", con) '--->You can give Emp_id instead of Textbox value.
  41.         Dim image As Byte() = DirectCast(command.ExecuteScalar(), Byte())
  42.         stream.Write(image, 0, image.Length)
  43.         con.Close()
  44.         Dim bitmap As New Bitmap(stream)
  45.         PictureBox2.Image = bitmap '--->I have used another picturebox to display image from database.
  46.     End Sub
  47.     'Thats all, You can place a linklabel below the picturebox if you to change photo and update it in database.
Regards,
Prathap
Jan 6 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Anand Ganesh | last post by:
HI All, I have an Image. I want to clip a portion of it and copy to another image. How to do this? I know the bounding rectangle to clip. Any suggestions please. Thanks for your time and...
1
by: Novice | last post by:
I'm afraid I will incur the wraith of Mr. Powell on this one - but I did read his #1 FAQ and some others and I still can't figure this out. I created this little c# app. and I have a PictureBox...
3
by: dale zhang | last post by:
Hi, I am trying to read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp The article author is using PictureBox for windows...
2
by: Marc Solé | last post by:
Hello, I want to insert an image to a specific column of a dataGridWiew. I explain what I'm doing: - I define the ColumnType as a DataGridViewImageColumn. - I select the image (an icon of...
3
by: CD | last post by:
An application is logging faxes sent in SQL2000 image column type. I have found code on the net but what it is doing is prompting to save to local which is fine for single page image. Not good...
3
by: Chris | last post by:
I need to load an rtf file to my sql database (into image type column). now I am using external tool textcopy.exe (launched within my application) Is it possible (how to do that) to write my own...
0
by: Andrew | last post by:
Hello Ive been messing around with a simple raw image viewer using Pil and Tkinter However I am running into problems displaying the images they appear to be not correct I believe it is cause of...
0
by: Iain | last post by:
Hi I am using Borland Developer 2006, C# web application. Fairly new to the .net platform and very new to repeaters. I have 2 repeaters on a page, both of which are filled from a database....
0
by: binuchirayath | last post by:
Hi All, I’m developing a windows application in which I have to implement a functionality for importing an image to a crystal report. I got two-three versions of code from Google. In all the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.