I have saved data as a byte array in my database, but when retrieving it, the byte array is incorrect. The column in the database is of type LONG BLOB.
** please dont copy paste from the ChatGPT solution. **
I have saved data as a byte array in my database, but when retrieving it, the byte array is incorrect. The column in the database is of type LONG BLOB.
** please dont copy paste from the ChatGPT solution. **
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted May 22, 2024, 5:52 AM EDT
Check this:
public byte[] GetByteArrayFromDataRow(DataRow dataRow, string columnName) { if (dataRow.Table.Columns.Contains(columnName)) { var base64String = dataRow.Field(columnName); return !string.IsNullOrEmpty(base64String) ? Convert.FromBase64String(base64String) : new byte[0]; } return new byte[0]; }Amit MohantyRank #112 · 20K reputationPosted May 21, 2024, 9:42 AM EDT
Hey Ishika, you please provide the code to save an image or PDF file to a database so that we can better understand the issue?
Ishika TiwariRank #298 · 8.4K reputationPosted May 22, 2024, 1:32 AM EDT
In obj. TINCopies, I am storing a byte array of a PDF. I convert it to base64 to save in the database.
Now I am facing a problem retrieving this byte array.
TINCopies = GetByteArrayFromDataRow(DataRow, "TINCopies"),public byte[] GetByteArrayFromDataRow(DataRow dataRow, string columnName) { if (dataRow.Table.Columns.Contains(columnName)) { return dataRow.Field(columnName) ?? new byte[0]; } return new byte[0]; }Thanks for your response !