Search code examples
c#.net-8.0.net-framework-version

.NET 8 Byte[] DataType in DataSet is missing. Is it by purpose?


Edit : Here's the properties of DataSet, DataTable's column properties from .NET 8 project. System.Byte[] is missing.

Byte array missing.

I store image thumbnail in mySQL in blob while display the thumbnail in my report via dataset bytearray. Is it missing by purpose? If yes what is the alternative?

And here's the properties of DataSet, DataTable's column properties from .NET Framework project. System.Byte[] is there. I have another .NET 8 project that also uses report binded with DataSet, it is also missing.

.NET Framework DataSet

I checked my previous project, it is there. Or perhaps it is wrong setting?


Solution

  • It does appear that you have happened upon a bug so you should probably report that to Microsoft (Help -> Send Feedback - Report a Problem in VS). In the meantime, I have a workaround for you.

    I just tried with a SQL Server database and, if the table and column were generated directly from the database, the column data type was set to System.Byte[], as it should be. That type was not in the drop-down list though, as your screenshot shows. That means that it cannot be selected if you have changed the data type or are creating the column manually. It can be done manually in the underlying code though. Close your DataSet designer for a start and then follow the instructions below.

    Firstly, in the Solution Explorer, expand the node for your typed DataSet's XSD, then the designer code file, then the DataSet, then the DataTable containing the column and then double-click on the InitClass method. In that method, you'll find the code to create and add the DataColumns to the DataTable. In the line that creates your column, make sure it includes typeof(byte[]). Based on your screenshot, it probably currently includes typeof(object). Don't save those changes yet.

    Secondly, in the Solution Explorer, right-click the XSD node and select Open With and then one of the XML editor options. Towards the bottom of the XML file, you will find lines that define your columns something like this:

    <xs:element name="Image" msprop:Generator_UserColumnName="Image" msprop:Generator_ColumnPropNameInTable="ImageColumn" msprop:Generator_ColumnPropNameInRow="Image" msprop:Generator_ColumnVarNameInTable="columnImage" type="xs:base64Binary" minOccurs="0" />
    

    Image was the name of my column, so look for the appropriate column name in your case. Note the attribute above that says type="xs:base64Binary". It will specify a different type for your column but you need to change it to xs:base64Binary.

    You should now be able to Save All your changes and reopen your DataSet in the designer and see that the type of your column is now System.Byte[]. That's how it worked for me, anyway.