79629099

Date: 2025-05-19 15:59:39
Score: 1.5
Natty:
Report link

As @Ashetynw pointed out, the problem in my case was that I wasn't including the id column in the DataTable.

I was purposefully excluding it because I thought it was a good practice for an autoincremental id.

The error I was receiving seemed to imply that the SQL columns in the DB were not aligning with the ones I was constructing in the DataTable, since it said that string was not convertable to int. I made sure to align the columns I constructed in the DataTable with the values in the rows I provided. So the error was not there. I promised, I debugged the columns and rows and they aligned perfectly.

After reading the response from @Ashetynw, I realized that the missing id must be the problem, since adding the id column would align the int-expected column with the next column, which was in fact an int.

Since doing and INSERT in SQL providing an id to a table with an incremental id doesn't affect anything, since the table will just ignore the provided id and calculate the next id increment as usual, I just added the id to the columns and rows of the DataTable and the problem was completely solved.

TL:DR

Include the DB id column in your DataTable columns and provide whatever value in its rows, since it will get overridden by the autoincrement logic.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • User mentioned (1): @pointed
  • Low reputation (1):
Posted by: Delphoenyx