0
從多個數據庫的多個數據I有11訪問數據庫文件每一個具有20個項目需要被存儲在本地變量作爲 RejRsnStn(ⅰ)(原因)其中我代表站數1至11 & 原因就代表理性1至20讀取在vb.Net
我在下面的方式讀取這些數據:
Public Sub ReadReasonCodes()
'Station 1
For Reason = 1 To 20
DatafileStn = "E:\DATANetwork\DATAStation_1.accdb;Jet OLEDB:Database Password=xxxxxxxx"
Dim ConnstringStn As String = provider & DatafileStn
connstringwrkstn = ConnstringStn
myConnection.ConnectionString = ConnstringStn
myConnection.Open()
str = "SELECT * FROM Table_Config WHERE StationNo = 1"
cmd = New OleDbCommand(str, myConnection)
dr = cmd.ExecuteReader
While dr.Read()
RejRsnStn1(Reason) = If(IsDBNull(dr("RejectionReason" & Reason)), "NA", dr("RejectionReason" & Reason))
End While
myConnection.Close()
Next
'Station 2
For Reason = 1 To 20
DatafileStn = "E:\DATANetwork\DATAStation_2.accdb;Jet OLEDB:Database Password=xxxxxxxx"
Dim ConnstringStn As String = provider & DatafileStn
connstringwrkstn = ConnstringStn
myConnection.ConnectionString = ConnstringStn
myConnection.Open()
str = "SELECT * FROM Table_Config WHERE StationNo = 2"
cmd = New OleDbCommand(str, myConnection)
dr = cmd.ExecuteReader
While dr.Read()
RejRsnStn2(Reason) = If(IsDBNull(dr("RejectionReason" & Reason)), "NA", dr("RejectionReason" & Reason))
End While
myConnection.Close()
Next
End Sub
能否請您指導我用簡潔的實現方法具d。
在此先感謝。 Prashant。
將所有連接內容移到循環之外。 – Gustav
令我難以置信的是,你使用循環作爲原因代碼,但完全無法將它們用於工作站ID。 –
我投票結束這個問題作爲題外話,因爲不,你不能haz德codez。 –