Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim objConn As New System.Data.SqlClient.SqlConnection
Dim dtAdapter As System.Data.SqlClient.SqlDataAdapter
Dim dt As New DataTable
Dim ds As New DataSet
Dim objCmd As New SqlCommand
Dim intNumRows As Double
Dim strConnString, strqr, aaaaa As String
strConnString = "Server=IT-04S\SQLEXPRESS;UID=TestVB;PASSWORD=11111;database=TestVB;Max Pool Size=400;Connect Timeout=600;"
objConn = New System.Data.SqlClient.SqlConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT IdEmp,NameEmp FROM ReportSl "
aaaaa = objCmd.ExecuteScalar
dtAdapter = New System.Data.SqlClient.SqlDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
For i = 0 To dt.Rows.Count - 1
strSQL = "SELECT sum(SUM_CN) FROM QDAILY WHERE CODE = '" & aaaaa & "'"
objCmd = New SqlCommand(strSQL, objConn)
Try
intNumRows = objCmd.ExecuteScalar()
Label4.Text = intNumRows.ToString()
Me.Label8.Text = intNumRows
Catch ex As Exception
Me.Label8.Text = intNumRows
End Try
' '''''''''''''''''''''''''รวมค่าเสร็จแล้ว บัณทึกลงฐานข้อมูล''''''''''''''''''''''''''''''
strqr = "UPDATE ReportSL SET CNsum = " & Me.Label8.Text & " WHERE IdEmp = '" & aaaaa & "'"
objCmd = New SqlCommand(strqr, objConn)
Try
objCmd.ExecuteNonQuery()
Me.Label3.Text = "อัพเดทข้อมูลสำเร็จ"
Catch ex As Exception
Me.Label3.Text = "ไม่สามารถบันทึกข้อมูล"
End Try
Next
End Sub