Question:When one executes a stored proc against MS SQL Server, the recordset comes with some type info. Clients are capable of retrieving that type info, e. g. like this (C#/.NET):
Specifically in the .NET client, there is
AllowDBNullin retrieved column properties, but in the scenario above it’s unreliable – it comes across as
trueboth for columns that came from nullable fields, and for columns that came from nonnullable fields. Is this a limitation of the .NET client, or a shortcoming of the underlying protocol?
Answer:This is a limitation of
The TDS protocol does return this information, as you can see in the specification.
SqlDataReaderwill return this information via
GetSchemaTable. But it does not make its way to a table filled using a
You can see this with the following code
falseand the second as
I would advise you in any case to avoid
SqlDataAdapter, as it is only actually useful in data-binding UI scenarios. In back-end code, just use a
SqlDataReader, or even better: use an ORM such as Dapper or Entity Framework, which will sort out all of this kind of thing for you.
If you have better answer, please add a comment about this, thank you!