question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting the value DbParameter.DbType to DbType.Time property fails after setting the Value property

See original GitHub issue

Describe 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:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ErikEJcommented, Oct 15, 2019

@cheenamalhotra Is this “up for grabs” ? Considering giving it a go.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found