Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameter of C# DateTime to SQL Server 2005?

How do I pass C# DateTime values (FromCreateDate and ToCreateDate) to SQL Server 2005 in order to select from a view ?

The result set CreateDate column must be between FromDateDate and ToCreateDate.

like image 350
odiseh Avatar asked Oct 19 '10 07:10

odiseh


1 Answers

Just set the parameter type to SqlDbType.DateTime

e.g

SqlCommand cmd = new SqlCommand("Select * From dbo.MyView Where createDate = @FromDate", SqlCon);
cmd.Parameters.Add(new SqlParameter(@FromDate, SqlDbType.DateTime));
cmd.Parameters["@FromDate"].Value = fromDate;
like image 141
codingbadger Avatar answered Sep 24 '22 17:09

codingbadger