After repairing my Visual Studio 2019, it executes some of the code and skips over others. I am thinking this behavior is caused by one or more Option settings. Can someone please help with this?
Here is the method where this occurs:
<code>Dim FName As String = ""
With MainMenu.OpenFileDialog1
.DefaultExt = "xlsx"
.Filter = "Excel files (*.xlsx)|*.xlsx"
.InitialDirectory = My.Settings.XLPath
If .ShowDialog = DialogResult.Cancel Then
Exit Sub
End If
FName = .FileName
My.Settings.XLPath = Replace(FName, .SafeFileName, "")
My.Settings.Save()
End With
Dim Tbl As New DataTable
Dim ShtName As String = ""
Dim CN As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & FName &
";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1""")
CN.Open()
Dim TblLst As DataTable = CN.GetSchema("Tables")
If TblLst.Rows.Count > 0 Then
ShtName = TblLst.Rows(0)("TABLE_NAME").ToString
End If
Dim ODBCmd As OleDbCommand = New OleDbCommand("Select * From [" & ShtName & "]", CN)
Dim ADP As OleDbDataAdapter = New OleDbDataAdapter(ODBCmd)
ADP.Fill(Tbl)
Debug.WriteLine("Rows in Tbl: " & Tbl.Rows.Count)
CN.Close()
For Each Col As DataColumn In Tbl.Columns
Debug.WriteLine(Col.ColumnName)
Next
</code>
<code>Dim FName As String = ""
With MainMenu.OpenFileDialog1
.DefaultExt = "xlsx"
.Filter = "Excel files (*.xlsx)|*.xlsx"
.InitialDirectory = My.Settings.XLPath
If .ShowDialog = DialogResult.Cancel Then
Exit Sub
End If
FName = .FileName
My.Settings.XLPath = Replace(FName, .SafeFileName, "")
My.Settings.Save()
End With
Dim Tbl As New DataTable
Dim ShtName As String = ""
Dim CN As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & FName &
";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1""")
CN.Open()
Dim TblLst As DataTable = CN.GetSchema("Tables")
If TblLst.Rows.Count > 0 Then
ShtName = TblLst.Rows(0)("TABLE_NAME").ToString
End If
Dim ODBCmd As OleDbCommand = New OleDbCommand("Select * From [" & ShtName & "]", CN)
Dim ADP As OleDbDataAdapter = New OleDbDataAdapter(ODBCmd)
ADP.Fill(Tbl)
Debug.WriteLine("Rows in Tbl: " & Tbl.Rows.Count)
CN.Close()
For Each Col As DataColumn In Tbl.Columns
Debug.WriteLine(Col.ColumnName)
Next
</code>
Dim FName As String = ""
With MainMenu.OpenFileDialog1
.DefaultExt = "xlsx"
.Filter = "Excel files (*.xlsx)|*.xlsx"
.InitialDirectory = My.Settings.XLPath
If .ShowDialog = DialogResult.Cancel Then
Exit Sub
End If
FName = .FileName
My.Settings.XLPath = Replace(FName, .SafeFileName, "")
My.Settings.Save()
End With
Dim Tbl As New DataTable
Dim ShtName As String = ""
Dim CN As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & FName &
";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1""")
CN.Open()
Dim TblLst As DataTable = CN.GetSchema("Tables")
If TblLst.Rows.Count > 0 Then
ShtName = TblLst.Rows(0)("TABLE_NAME").ToString
End If
Dim ODBCmd As OleDbCommand = New OleDbCommand("Select * From [" & ShtName & "]", CN)
Dim ADP As OleDbDataAdapter = New OleDbDataAdapter(ODBCmd)
ADP.Fill(Tbl)
Debug.WriteLine("Rows in Tbl: " & Tbl.Rows.Count)
CN.Close()
For Each Col As DataColumn In Tbl.Columns
Debug.WriteLine(Col.ColumnName)
Next
When it get to the line that fills the datatable Tbl, it does not execute that line and returns to the form that called this method.
6