Hi @BenTam-3003 , Welcome to Microsoft Q&A,
Because the StudentID you selected is int32.
Try using tostring() to convert it to string first.
string tmp = string.Format("{0}", row.Field<int>("StudentID").ToString());
In this code, I've replaced row.Field<string>("StudentID") with row.Field<int>("StudentID").ToString() to explicitly convert the integer value to a string before using it in the string.Format method. This should resolve the casting issue.
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.