Hi i want to save a picture of employee in SQL server Database in my college project payroll system, Please Help me in this matter and give me one example of this.

Dear, I use following codes in project to save and retrieve picture in sql

If PictureBox1.Image Is Nothing Then
            MsgBox("Get Picture First !! ")
            Me.btnBrows.Focus()
            Exit Sub
        Else
            If Len(Me.TextBox1.Text) > 0 Then

                str = "select * from employees where sno =" & Val(Me.TextBox1.Text)
                dt = GetTable(str)
                Dim iimage As Array

                If Not PictureBox1.ImageLocation Is Nothing Then
                    iimage = IO.File.ReadAllBytes(PictureBox1.ImageLocation)
                End If

                If (dt.Rows.Count >= 1) Then
                    Dim cmd As New SqlClient.SqlCommand("update employees set Name=@name, city=@city, phone=@phone where sno = " & Val(TextBox1.Text), con)
                    cmd.Parameters.Add(New SqlClient.SqlParameter("@name", SqlDbType.VarChar)).Value = Trim(Me.TextBox2.Text)
                    cmd.Parameters.Add(New SqlClient.SqlParameter("@city", SqlDbType.VarChar)).Value = Trim(Me.TextBox3.Text)
                    cmd.Parameters.Add(New SqlClient.SqlParameter("@phone", SqlDbType.VarChar)).Value = Trim(Me.TextBox4.Text)
                    cmd.ExecuteNonQuery()
                    MsgBox("Record updated !! ", MsgBoxStyle.Exclamation)

                Else
                    Dim cmd As New SqlClient.SqlCommand("Insert Into employees (sno,Name, city, phone,img) Values (@sno,@Name, @city,@phone, @img)", con)
                    cmd.Parameters.Add(New SqlClient.SqlParameter("@sno", SqlDbType.Int)).Value = Val(Me.TextBox1.Text)
                    cmd.Parameters.Add(New SqlClient.SqlParameter("@name", SqlDbType.VarChar)).Value = Trim(Me.TextBox2.Text)
                    cmd.Parameters.Add(New SqlClient.SqlParameter("@city", SqlDbType.VarChar)).Value = Trim(Me.TextBox3.Text)
                    cmd.Parameters.Add(New SqlClient.SqlParameter("@phone", SqlDbType.VarChar)).Value = Trim(Me.TextBox4.Text)
                    cmd.Parameters.Add(New SqlClient.SqlParameter("@img", SqlDbType.Image)).Value = IO.File.ReadAllBytes(PictureBox1.ImageLocation)
                    cmd.ExecuteNonQuery()
                    MsgBox("Record inserted !! ", MsgBoxStyle.Information)
                End If

            End If
        End If

        If Not PictureBox1.ImageLocation Is Nothing Then

            Dim cmd As New SqlClient.SqlCommand("update employees set Name=@name, city=@city, phone=@phone, img=@img where sno = " & Val(TextBox1.Text), con)
            cmd.Parameters.Add(New SqlClient.SqlParameter("@name", SqlDbType.VarChar)).Value = Trim(Me.TextBox2.Text)
            cmd.Parameters.Add(New SqlClient.SqlParameter("@city", SqlDbType.VarChar)).Value = Trim(Me.TextBox3.Text)
            cmd.Parameters.Add(New SqlClient.SqlParameter("@phone", SqlDbType.VarChar)).Value = Trim(Me.TextBox4.Text)
            cmd.Parameters.Add(New SqlClient.SqlParameter("@img", SqlDbType.Image)).Value = IO.File.ReadAllBytes(PictureBox1.ImageLocation)
            cmd.ExecuteNonQuery()

        End If

If you need more help, you can reach me on hotmail and yahoo messenger as
tqmd2003@hotmail.com
tqmd2003@yahoo.com

This article has been dead for over six months. Start a new discussion instead.