im working on an attendance monitoring system and im having a hard time on saving a picture on my picture box, at the "add employee" section of my program.
i want to save the path of the picture on the emphoto field of my database and the actual photo on a separate folder named "photos". here's my code for my "add employee" button thats always having the same errors.
Imports System.Data.SqlClient
Public Class Form6
Dim conn As New SqlConnection("Data Source = .\sqlexpress ; Initial Catalog = dummudb ; Integrated Security = SSPI ")
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
conn.Open()
''check if employee name entered is already registered
Dim check As Integer
For i As Integer = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.Empty
If TextBox1.Text = DataGridView1.Item(1, i).Value And TextBox2.Text = DataGridView1.Item(2, i).Value Then
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.CadetBlue
check = 1
End If
Next
If check <> 1 Then ''if employee name is not yet registered, insert data on the database
Dim sql As New SqlCommand("Insert into employee values ('" & Label10.Text & "' , '" & TextBox1.Text & "' , '" & TextBox2.Text & "' , '" & TextBox3.Text & "' , '" & TextBox4.Text & "' , '" & TextBox5.Text & "' , '" & ComboBox1.Text & "' , 'C:\Users\randy\Desktop\EAMS\photos\'" & TextBox1.Text & "'+'" & TextBox2.Text & "'+'" & TextBox3.Text & "'.jpeg')", conn)
sql.CommandType = CommandType.Text
Dim adapt As New SqlDataAdapter
adapt.InsertCommand = sql
adapt.InsertCommand.ExecuteNonQuery()
Dim sql3 As New SqlCommand("Select * from employee", conn)
sql3.CommandType = CommandType.Text
Dim adapt3 As New SqlDataAdapter
adapt3.SelectCommand = sql3
adapt3.SelectCommand.ExecuteNonQuery()
Dim dset2 As New DataSet
adapt3.Fill(dset2, "employee")
DataGridView1.DataSource = dset2.Tables("employee")
PictureBox1.Image.Save("C:\Users\randy\Desktop\EAMS\photos\'" & TextBox1.Text & "' '" & TextBox2.Text & "' '" & TextBox3.Text & "'.jpeg")
ElseIf check = 1 Then
''if employee name is already registered
MsgBox("Employee already registered!", MsgBoxStyle.Critical)
End If
conn.Close()
''display the next available employee number on label 10
Dim row As Integer
row = DataGridView1.RowCount - 1
Label10.Text = DataGridView1.Item(0, row).Value + 1
''clear all textbox fields
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
End Sub