HOME > ASP > ASP Forum > จะทำยังไงดีค่ะ ให้ Gridview แสดงข้อมูลทั้งหมดโดยมีตัวแปรที่เป็นอาเรย์ โดยที่อาเรย์เก็บค่า 2 ตำแหน่งแล้วนำค่าที่ได้ไปหาค่าใน SQL เพื่อให้ทำการ Query ข้อมูลออกมา
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
Dim dtReader As SqlDataReader
For i As Integer = 0 To ArrDep.Length - 1
If ArrDep(i) <> "" Then
strSQL = "select Employee.Department_Name,Employee.Employee_ID,Employee.Employee_FirstName,Employee.Employee_LastName," +
"Time.Card_Date,Emp_ShiftWork.WorkTime_ID,Time.Card_Day_Name,Time.Card_Time_IN,Time.Card_Time_Out,Time.Card_Over_Time," +
" Time.Card_Time_Late,'' AS Vacation_Name From Employee LEFT Join Time ON Employee.Employee_ID = Time.Employee_ID LEFT JOIN Emp_ShiftWork ON" +
" Employee.Employee_ID = Emp_ShiftWork.Employee_ID AND Time.Card_Date = Emp_ShiftWork.WorkTime_Date where Employee.Employee_Status = 'TRUE' AND Employee.Department_Name = '" & ArrDep(i) & "'AND Time.Card_Date = '" & Convert.ToString(call1.SelectedDate) & "'" +
" UNION" +
" select Employee.Department_Name,Employee.Employee_ID,Employee.Employee_FirstName,Employee.Employee_LastName," +
" Emp_Vacation.Vacation_Date AS Card_Date,'' AS WorkTime_ID,'' AS Card_Day_Name,'' AS Card_Time_IN,'' AS Card_Time_Out," +
" '' AS Card_Over_Time,'' AS Card_Time_Late,Vacation.Vacation_Name From Employee LEFT Join Emp_Vacation ON" +
" Employee.Employee_ID = Emp_Vacation.Employee_ID LEFT JOIN Vacation ON Emp_Vacation.Vacation_ID = Vacation.Vacation_ID" +
" where Employee.Employee_Status = 'TRUE' AND Employee.Department_Name = '" & ArrDep(i) & "' AND Emp_Vacation.Vacation_Date = '" & Convert.ToString(call1.SelectedDate) & "'"
objCmd = New SqlCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
'*** Data to GridView ***'
myGridView.DataSource = dtReader
myGridView.DataBind()
dtReader.Close()
dtReader = Nothing
End If
Next
End Sub