I'm getting a bizarre error in my code, and I was wondering if somebody knew what I could look for to fix it
This is the line that's erroring. record is a DataTable, Rows(0) is checked to be valid, and fcurr is declared as a String
If IsDBNull(record.Rows(0).Item("fcurr")) Then fcurr = Nothing Else fcurr = record.Rows(0).Item("fcurr")
System.InvalidCastException was unhandled
Message="Specified cast is not valid."
Source="TestApplication"
StackTrace:
at TestApplication.SalesOrders.OrderHeader.Load(SqlConnection dbServer, SqlTransaction dbTrans, Int32 OrderNumber) in C:\MarqDev\TestApplication\SalesOrders\OrderHeader.vb:line 530
at TestApplication.DevTools.OrderFormTest.Button1_Click(Object sender, EventArgs e) in C:\MarqDev\TestApplication\TestApplication.DevTools\OrderFormTest.vb:line 11
InnerException:
I don't understand, because there's no casting being done, fcurr is populated with the string "EUR", and if I press F5 to continue to the code, it continues on the same line without generating the exception.
I'm seeing this occur a couple of times on similar lines. Happens in debug mode, and also in a Release compile
Does anybody have any idea what I can look at? As I said, if I continue the code from the breakpoint, it carries on without a problem
Edit:
That also occurs on Integer and Double fields.
Edit 2:
The DataTable is constructed from a SqlDataAdapter querying a table from an SQL Server
Edit 3:
Ahhh, actually, whilst the debugger is breaking on this line, this isn't actually the line causing the problem. I think I know what it is now, and it's related to the data type of the previous field