Here is some code I'm using to add employee pictures to a SQL
database  and how I'm displaying the employees by department in a
datagrid.  Hope this helps
Add Image

 Dim intImageSize As Int64
        Dim strImageType As String
        Dim ImageStream As Stream

        ' Gets the Size of the Image

        intImageSize = File1.PostedFile.ContentLength

   ' Gets the Image Type
        strImageType = File1.PostedFile.ContentType

        ' Reads the Image

        ImageStream = File1.PostedFile.InputStream

        Dim ImageContent(intImageSize) As Byte
        Dim intStatus As Integer

        intStatus = ImageStream.Read(ImageContent, 0, intImageSize)

        ' Create Instance of Connection and Command Object
        Dim myConnection As New SqlConnection
(ConfigurationSettings.AppSettings("LSData_Media"))

        Dim CommandText As String = "INSERT INTO EmployeePhoto " _
                                   & "(emp_ID, EmpImage, ImageType) "
_
                                   & "VALUES (@emp_ID, @EmpImage,
@ImageType)"

        Dim sqlCommand As New SqlCommand(CommandText, myConnection)

        sqlCommand.Parameters.Add(New SqlParameter("@emp_ID",
SqlDbType.VarChar, 50))
        sqlCommand.Parameters.Add(New SqlParameter("@EmpImage",
SqlDbType.Image))
        sqlCommand.Parameters.Add(New SqlParameter("@ImageType",
SqlDbType.VarChar, 50))
        sqlCommand.Parameters("@emp_ID").Value =
cboName.SelectedItem.Value
        sqlCommand.Parameters("@EmpImage").Value = ImageContent
        sqlCommand.Parameters("@ImageType").Value = strImageType

        Try
            myConnection.Open()
            sqlCommand.ExecuteNonQuery()
            myConnection.Close()
            Response.Write("New person successfully added!")
        Catch SQLexc As SqlException
            Response.Write("Insert Failed. Error Details are: " &
SQLexc.ToString())
        End Try

Display Image in Datagrid with Imagebutton

Public Sub FillDataList()
        'Fill Employee Birthdays with Current Month

        Dim sqlConn As SqlConnection
        sqlConn = DataLayer.GetSQLConnection("LSData")
        Dim DEPT As New SqlParameter("@DEPT", SqlDbType.Text)
        DEPT.Value = Department


        Dim sqlCmd As New SqlCommand("z_EmpPhoto", sqlConn)
        sqlCmd.CommandType = CommandType.StoredProcedure
        sqlCmd.Parameters.Add(DEPT)
        Dim sqlDS As New DataSet()
        Dim sqlDA As New SqlDataAdapter()

        sqlDA.SelectCommand = sqlCmd
        sqlDA.Fill(sqlDS, "FillData")
        Me.DataList1.DataSource = sqlDS
        Me.DataList1.DataBind()
        sqlConn.Close()

    End Sub

On Aug 16, 5:01 am, ngugi <[email protected]> wrote:
> am handling an application that will be used as a student manager, and
> i need to store the student`s photograph as well as the
> guardian`s.....its a cropper for me :=((....could anyone show me how
> to go about attaching an image,that way an image can be
> scanned,checked for size e.g 300 *300 dpi and then save it in a
> database, and what is the most suitable data type for this type of
> complex data? thank you

Reply via email to