Setting the value DbParameter.DbType to DbType.Time property fails after setting the Value property
See original GitHub issueDescribe the bug
Setting the value DbParameter.DbType to DbType.Time property is failing after setting the Value property
No exception and not a breaking issue.
To reproduce
using Microsoft.Data.SqlClient;
using System;
using System.Data;
namespace DbParameterDbTypeTimeTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
TestDbTypeTimeAssignment();
Console.ReadLine();
}
static void TestDbTypeTimeAssignment()
{
using (var connection = new SqlConnection(""))
{
using (var command = connection.CreateCommand())
{
var parameter = command.CreateParameter();
parameter.ParameterName = "ParameterName";
// Here I first set the value of the parameter to any TimeStamp
parameter.Value = DateTime.UtcNow.TimeOfDay;
// After I assign the value at line 26, the DbType property is "AUTOMATICALLY"
// set to DbType.Time.
// The issue is below, I have an explicit call on my ORM to set the DbParameter.DbType
// value to DbType.Time, and the result afterwards is DbType.DateTime
parameter.DbType = DbType.Time;
command.Parameters.Add(parameter);
}
}
}
}
}
Expected behavior
I would expect that after setting the DbParameter.DbType
property to DbType.Time
, the the value of the DbParameter.DbType
property should be DbType.Time
(not DbType.DateTime
).
Further technical details
#region Assembly Microsoft.Data.SqlClient, Version=1.0.19128.1, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5 // C:\Users\MIPEN.nuget\packages\microsoft.data.sqlclient\1.0.19128.1-preview\ref\netcoreapp2.1\Microsoft.Data.SqlClient.dll #endregion
Additional context Explained in the code above.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Convert a object variable to a DBType before setting ...
Sometimes the object contains a value which does not match the parameter's DBType. For instance, a parameter is of type smallint and the...
Read more >Configuring parameters and parameter data types
The following table shows the inferred Parameter type based on the object passed as the Parameter value or the specified DbType .
Read more >Issues with SQL 2008 Time DataType at Save, Page 1
Getting the value from the database doesn't seem to be the problem but when it's saved I ... SqlParameter, DbType set property ->...
Read more >OracleCommand Object
An application can bind the data and have ODP.NET infer both the DbType and OracleDbType properties from the .NET type of the parameter...
Read more >Dapper Parameter, SQL Injection, Anonymous and ...
Dapper allows specifying parameters in querying methods to avoid SQL Injection. Learn more about how to use anonymous, dynamic, string, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Related issues for reference: https://github.com/dotnet/corefx/issues/21279 https://github.com/dotnet/docs/issues/4474
@cheenamalhotra Is this “up for grabs” ? Considering giving it a go.