Importing a spreadsheet, but having trouble.
- by Chris Phelps
I have a form that allows a user to import a spreadsheet. This spreadsheet is generally static when it comes to column headers, but now the users want to be able to include an optional column (called Notes). My code crashes when I try to read the column from the spreadsheet if it doesn't exist.
Dim objCommand As New OleDbCommand()
objCommand = ExcelConnection() 'function that opens spreadsheet and returns objCommand
Dim reader As OleDbDataReader
reader = objCommand.ExecuteReader()
While reader.Read()
Dim Employee As String = Convert.ToString(reader("User"))
Dim SerialNUM As String = Convert.ToString(reader("serialno"))
**Dim Notes As String = Convert.ToString(reader("notes"))**
If the spreadsheet contains a Notes column, all goes well. If not, crash. How can I check to see if the Notes column exists in the spreadsheet to avoid the crash?