Click here to Skip to main content
12,511,494 members (50,739 online)
Click here to Skip to main content
Add your own
alternative version


20 bookmarked

Handling Image and Employee Records and Show in Datagrid and Image Control

, 14 Oct 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Handling Image With Employee Records and Show in Datagrid and Image Control
Sample screenshot


In this article, I create two classes, one is EmployeeInformation and another is EmployeeManager. EmployeeInformation class structure looks like this:

Imports System
Imports System.IO.Stream
Imports System.Data.SqlClient
Public Class EmployeeInformation
Inherits Connect
Public Id As Integer
Public Name As String
Public Address As String
Public ContactNo As Long
Public Designation As String
Public City As String
Public Image() As Byte
Public Shared Function GetImpId() As Integer
Connect.Qry = "Select Max(Id) from EmployeeRecord"
Connect.cmd.Connection = con
Connect.cmd.CommandText = Qry
GetImpId = Connect.cmd.ExecuteScalar
End Function
End Class

And EmployeeManager class structure looks like this:

Public Class EmployeeManager
Inherits Connect
Public Shared Sub CreateRecord(ByVal EmpObj As EmployeeInformation)
Connect.Qry = "insert into EmployeeRecord(Name,Designation,Address,ContactNo,City,image)
values (@Name,@Designation,@Address,@ContactNo,@City,@image)"
Connect.cmd.Connection = con
Connect.cmd.CommandText = Qry
Dim prmName As New SqlParameter("@Name", SqlDbType.VarChar)
prmName.Value = EmpObj.Name
Dim prmDesignation As New SqlParameter("@Designation", SqlDbType.VarChar)
prmDesignation.Value = EmpObj.Designation
Dim prmAddress As New SqlParameter("@Address", SqlDbType.VarChar)
prmAddress.Value = EmpObj.Address
Dim prmContactNo As New SqlParameter("@ContactNo", SqlDbType.VarChar)
prmContactNo.Value = EmpObj.ContactNo
Dim prmCity As New SqlParameter("@City", SqlDbType.VarChar)
prmCity.Value = EmpObj.City
Dim prmImage As New SqlParameter("@image", SqlDbType.Image)
prmImage.Value = EmpObj.Image
End Sub
Public Shared Sub UpdateRecord(ByVal EmpObj As EmployeeInformation)
Connect.Qry = "Update EmployeeRecord set 
<a href="mailto:Name=@Name,Designation=@Designation%22%3EName=@Name,Designation=@Designation,Address=@Address,ContactNo=@ContactNo,City=@City,image=@image">mailto:Name=@Name,Designation=@Designation">Name=@Name,Designation=@Designation,

and another class called Connect that is used for declaring ConnectionObject and CommandObject. That looks like this:

Public Class Connect
Protected Shared con As New SqlConnection(ConfigurationSettings.AppSettings("ConStr"))
Protected Shared cmd As New SqlCommand
Protected Shared Qry As String
End Class

These is the structure of the class. Now for image display in Datagrid, we use:

Function FormatUrl. i.e. look like this
Shared Function FormatUrl(ByVal strArg) As String
Return ("RealImagePage.aspx?id=" & strArg)
End Function

Here I use RealImagePage.aspx in this page Response.BinaryWriter write the image, and that image is returned by id on Datagrid. In Datagrid, I create Template column that contains image control.

<asp:Image width=90 Height=100 ImageUrl='<% # FormatUrl(DataBinder.Eval

This will call the Image in Datagrid column. The same thing for ImageControl. I write this for showing image in Image control.


To Clear All TextBox In Form, I write this sub.

Sub ClearField()
Dim ctl As Control
For Each ctl In Me.FindControl("Form1").Controls
If (Not ctl Is System.DBNull.Value) Then
'Reset TextBox On The Form
If (ctl.GetType.ToString.ToLower.IndexOf("textbox") > 0) Then
CType(ctl, TextBox).Text = String.Empty
End If
End If
End Sub


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Navin Singhwane
Web Developer
India India

You may also be interested in...


Comments and Discussions

QuestionHandling Image and Employee Records and Show in Datagrid and Image Control Pin
priom222-Jun-13 4:08
memberpriom222-Jun-13 4:08 
QuestionHow to implement same to insert multiple images for a single user? Pin
zakzapakzak2-May-08 1:35
memberzakzapakzak2-May-08 1:35 
GeneralExcellent Contribution [modified] Pin
cgilf2-Aug-06 10:39
membercgilf2-Aug-06 10:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160929.1 | Last Updated 14 Oct 2010
Article Copyright 2006 by Navin Singhwane
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid