I have a small program to "download" database tables to Excel.
I want to add the column type to the second line and I tried it with the following function. It works fine but the GetDataTypeName(i) returns only int, nvarchar but I need the complete type specification like this
nvarchar(255), decimal(19, 8)
Is there another function to get this from the database ?
SqlDataReader dataReader = command.ExecuteReader();
// adds the names and the types if the table has no values
if (!dataReader.HasRows || !withValues)
{
for (int i = 0; i < dataReader.FieldCount; i++)
{
names.Add(dataReader.GetName(i));
types.Add(dataReader.GetDataTypeName(i));
}
}
dataReader.GetSchemaTable()gives you full metadata for all columns..GetSchemaTable()(Not sure if it exposes precision/scale however)xlsx) file with a call as simple assheet.LoadFromDataTableas shown here. You can format the resulting columns as neededNumericPrecisionandNumericScalelisted on the documentation you linked