0

Error message

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:

  1. Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints

I tried ? dttable.GetErrors(0).RowError on debug mode and it says "Referenced object has a value of 'Nothing'."

  1. 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.

DDL of the target table

  • Really hard to give any real answer without knowing the data structures or sample query results. Starting with the basics though. That error message is giving you 3 different possible reasons for the error, your question seem to be focused on only one. Are you sure it's not another constraint causing the problem? – Hursey Oct 05 '22 at 19:25
  • @Hursey yes im pretty sure, the values didnt violate any null and unique rules, since the values follow nullable rules well, no unique constraints are set, only foreign key constraint to another table's primary key. – I Forgot My Name Oct 06 '22 at 01:56
  • @Hursey i had added the DDL of my target table for your reference – I Forgot My Name Oct 06 '22 at 02:03
  • So what exactly is dttable in this context. Where is that defined? You mention dataset in your question, how exactly is that connected to the result of this function? How are you calling this function. Is this error actually occurring withing this method or somewhere further up the call stack? The more I look at this question the more questions I have, something just seems a little off – Hursey Oct 06 '22 at 03:33
  • Never mind, i actually tried using MySqlDataAdapter and used it to fill into my data table which is dttable in this context. The problem is fixed. – I Forgot My Name Oct 06 '22 at 06:19

0 Answers0