Imports System
Imports System.Threading
Imports System.IO
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.OracleClient
Public Class Form3
Dim Thread1, Thread_Member, Thread_Loan As System.Threading.Thread
Dim Str_Query As String
Private Sub ProcessData()
Dim StrPathAccess1, StrPathAccess2 As String
Dim DirectoryFile As FileInfo
Dim Dr_Prov As DataRow = Nothing
StrPathAccess1 = "D:\database\"
ConOracle.Open()
Str_Query = "SELECT * FROM tbl_province ORDER BY prov_id ASC"
Da_Oracle.SelectCommand = New OracleCommand(Str_Query, ConOracle)
Try
Da_Oracle.Fill(Ds_Oracle, "province")
Dim i, x As Integer
For i = 0 To Ds_Oracle.Tables("province").Rows.Count - 1
Dr_Prov = Ds_Oracle.Tables("province").Rows(i)
StrPathAccess2 = StrPathAccess1 & Dr_Prov("prov_name_eng").ToString & "\women_fund.accdb"
DirectoryFile = New FileInfo(StrPathAccess2)
If DirectoryFile.Exists = True Then
LblProvince.Text = "กำลังประมวลผลจังหวัด" & Dr_Prov("prov_name").ToString
StrConAccess = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & StrPathAccess2 & ";Persist Security Info=False;"
Call ProcessRptMember(Dr_Prov("prov_id").ToString)
'DgvProcess.Rows(0).Cells(1).Value = i
'For x = 1 To 100
' DgvProcess.Rows(0).Cells(1).Value = x & " %"
' Me.Refresh()
' System.Threading.Thread.Sleep(100)
'Next
End If
StrPathAccess2 = ""
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
LblProvince.Text = ""
ConOracle.Close()
End Sub
Private Sub Form3_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Thread1.Abort()
End Sub
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DgvProcess.Rows.Add(3)
With DgvProcess
.Rows(0).Cells(0).Value = "สมาชิก"
.Rows(1).Cells(0).Value = "เงินกู้"
End With
Control.CheckForIllegalCrossThreadCalls = False
End Sub
Private Sub BtnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnProcess.Click
Dim Thread1 As New Thread(AddressOf ProcessData)
Thread1.Start()
End Sub
End Class
Code (VB.NET)
Public Sub ProcessRptMember(ByVal province As String)
Dim i As Integer
For i = 1 To 100
With Form3
.DgvProcess.Rows(0).Cells(1).Value = i & " %"
System.Threading.Thread.Sleep(100)
End With
Next
End Sub
ปัญหาก็คือมันขึ้น error ตามรูปด้านบนเพราะถ้าเอาโค๊ตที่วนลูปนำค่าตัวเลขเอาไปใส่ในกริด(ในส่วนที่เป็น sub แยกออกมา)
แต่ถ้านำโค๊ตนี้ไปไว้ใน Sub ProcessData จะไม่มีปัญหาอะไร เลยสงสัยว่ามันเกิดจากอะไร ทั้งๆที่ row และ cell ที่อ้างอิงนั้นถูกต้องแล้ว