Skip to content

SqlParameter - behaviour of Scale property for datetime2 parameters #2604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions xml/System.Data.SqlClient/SqlParameter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1229,11 +1229,13 @@ static void CreateSqlParameterLocaleId(){
<format type="text/markdown"><![CDATA[

## Remarks
The <xref:System.Data.SqlClient.SqlParameter.Scale%2A> property is used by parameters that have a <xref:System.Data.SqlDbType> of `Decimal`.
The <xref:System.Data.SqlClient.SqlParameter.Scale%2A> property is used by parameters that have a <xref:System.Data.SqlDbType> of `Decimal`, `DateTime2`, `DateTimeOffset`, or `Time`.

> [!WARNING]
> Data may be truncated if the <xref:System.Data.SqlClient.SqlParameter.Scale%2A> property is not explicitly specified and the data on the server does not fit in scale 0 (the default).

> For the `DateTime2` type, scale 0 (the default) will be passed as datetime2(7). There is currently no way to send a parameter as datetime2(0). Scales 1-7 work as expected.
> This problem applies to `DateTimeOffset` and `Time` as well.

You do not need to specify values for the <xref:System.Data.SqlClient.SqlParameter.Precision%2A> and <xref:System.Data.SqlClient.SqlParameter.Scale%2A> properties for input parameters, as they can be inferred from the parameter value. `Precision` and `Scale` are required for output parameters and for scenarios where you need to specify complete metadata for a parameter without indicating a value, such as specifying a null value with a specific precision and scale.

> [!NOTE]
Expand Down Expand Up @@ -2068,4 +2070,4 @@ FieldName = @OriginalFieldName
</Docs>
</Member>
</Members>
</Type>
</Type>