The above image shows the error image whenever I tried to execute the sql command to get data table in VB .NET as shown below: (note: sqlstr
and dttable
has been declared before function headers, therefore no declaration here)
Public Function retrieveProducts() As DataTable
sqlstr = "SELECT * FROM products;"
dttable = MysqlClient.DataHandler.GetDataTable(sqlstr, conn, True)
If Not IsNothing(dttable) Then
Return dttable
End If
Return Nothing
End Function
Before you guys link the problem to any "duplicate" question, I want to inform that I had browsed a ton of answers from similar questions and none of them worked for me. Here are the solutions I tried:
I tried
? dttable.GetErrors(0).RowError
on debug mode and it says "Referenced object has a value of 'Nothing'.
"
- I also tried removing constraints of data table in my program (putting the remove function before the
MysqlClient.DataHandler.GetDataTable
function causes nothing to be returned)
Note:
The solution for dataset.enforceConstraints = false
should be my last resort since my supervisor requested the program structure to revolve around MySqlClient data handler. If it's possible I wanted to resolve this without using data set.
As for the table itself, it has a foreign key constraint referencing to another table, the values in the table didnt violate any non-null and unique constraints. Besides that, other table with foreign key constraint too however, can be retrieved successfully. So I am confused with what is wrong.