After the first loop I get an error on command.executereader(), OleDbException occured, IErrorInfo.GerDescription failed with E)FAIL(0x80004005), error code -2147467259
Code:
Private Sub RefreshQuery(ByVal StrList As String)
Dim Tempconn As New OleDbConnection(System.Configuration.ConfigurationManager.AppSettings.Get("ConnectionString"))
Dim SQLTxt As String
Try
Tempconn.Open()
QueryCombo1.Items.Clear()
QueryCombo2.Items.Clear()
QueryCombo3.Items.Clear()
QueryCombo4.Items.Clear()
QueryCombo5.Items.Clear()
QueryCombo6.Items.Clear()
QueryCombo7.Items.Clear()
QueryCombo8.Items.Clear()
QueryCombo9.Items.Clear()
QueryCombo1.Text = Nothing
QueryCombo2.Text = Nothing
QueryCombo3.Text = Nothing
QueryCombo4.Text = Nothing
QueryCombo5.Text = Nothing
QueryCombo6.Text = Nothing
QueryCombo7.Text = Nothing
QueryCombo8.Text = Nothing
QueryCombo9.Text = Nothing
Do Until StrList = "UNK"
SQLTxt = "SELECT DISTINCT " & StrList & " FROM GHPAS4TG ORDER BY " & StrList & ";"
command = New OleDbCommand(SQLTxt, Tempconn)
dataReader = command.ExecuteReader()
If dataReader.HasRows Then
Select Case StrList
Case "Own"
Do While dataReader.Read
QueryCombo9.Items.Add(dataReader(StrList))
Loop
StrList = "UNK"
Case "TestDate"
Do While dataReader.Read
QueryCombo8.Items.Add(dataReader(StrList))
Loop
StrList = "Own"
Case "Coat"
Do While dataReader.Read
QueryCombo7.Items.Add(dataReader(StrList))
Loop
StrList = "TestDate"
Case "LgSm"
Do While dataReader.Read
QueryCombo6.Items.Add(dataReader(StrList))
Loop
StrList = "Coat"
Case "SMYS"
Do While dataReader.Read
QueryCombo5.Items.Add(dataReader(StrList))
Loop
StrList = "LgSm"
Case "MAOP"
Do While dataReader.Read
If dataReader(StrList).ToString = "-1" Then
QueryCombo4.Items.Add("UNK")
Else
QueryCombo4.Items.Add(dataReader(StrList).ToString)
End If
Loop
StrList = "SMYS"
Case "WallThk"
Do While dataReader.Read
If dataReader(StrList).ToString = "-1" Then
QueryCombo3.Items.Add("UNK")
Else
QueryCombo3.Items.Add(dataReader(StrList).ToString)
End If
Loop
StrList = "MAOP"
Case "Size"
Do While dataReader.Read
If dataReader(StrList).ToString = "-1" Then
QueryCombo2.Items.Add("UNK")
Else
QueryCombo2.Items.Add(dataReader(StrList).ToString)
End If
Loop
StrList = "WallThk"
Case "Designation"
Do While dataReader.Read
QueryCombo1.Items.Add(dataReader(StrList))
Loop
StrList = "Size"
End Select
Else
MessageBox.Show("Custom Query Data Error!", "Data Error!", MessageBoxButtons.OK)
End If
Loop
Catch ex As Exception
MessageBox.Show("Custom Query!" + Environment.NewLine + ex.Message, "Data Error!", MessageBoxButtons.OK)
'Debug.Print(ex.Message)
Finally
If command IsNot Nothing Then command = Nothing
If dataReader IsNot Nothing Then dataReader = Nothing
If Tempconn IsNot Nothing Then Tempconn.Close()
If Tempconn IsNot Nothing Then Tempconn = Nothing
End Try
End Sub