Dim sql As String
Dim dt As DataTable
Dim da As OleDbDataAdapter
sql = "Select emp_id From employee_admin"
da = New OleDbDataAdapter(sql, Conn)
dt = New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
Dim str As String
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim dd As Date = Today
str = "Select * From employee_detail Where datework=" & dd
cmd = New OleDbCommand(str, Conn)
dr = cmd.ExecuteReader
dr.Read()
If Not dr.HasRows Then
For r As Integer = 0 To DataGridView1.RowCount - 1
str = "Insert Into employee_detail(emp_id,datework) Values(@emp_id,@datework)"
cmd = New OleDbCommand(str, Conn)
With cmd
.Parameters.AddWithValue("emp_id", CStr(DataGridView1.Rows(r).Cells(0).Value))
.Parameters.AddWithValue("datework", dd)
End With
cmd.ExecuteNonQuery()
Next
End If
พอรันแล้ว เออเรอ Parameter @emp_id has no default value.
Dim str As String
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim dd As DateTime = DateTime.Today
str = "Select * From employee_detail Where datework=@today"
cmd = New OleDbCommand(str, Conn)
cmd.Parameters.AddWithValue("@today", dd)
dr = cmd.ExecuteReader()
dr.Read()
If Not dr.HasRows Then
For Each drow As DataRow In dt.Rows
str = "Insert Into employee_detail(emp_id,datework) Values(@emp_id,@datework)"
cmd = New OleDbCommand(str, Conn)
cmd.Parameters.AddWithValue("@emp_id", drow("ฟิลนั้นแหละ").ToString())
cmd.Parameters.AddWithValue("@datework", dd)
cmd.ExecuteNonQuery()
Next
End If