Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Passing Date Parameter as SqlCommand Parameter in C#

$
0
0

How to pass Date parameter from asp.net C# to sql server using sql command parameters

Error i am getting is "Invalid cast from 'DateTime' to 'Int32'.Couldn't store <10/3/2017 12:00:00 AM> in Date Column.  Expected type is Int32."

The Code is

Cmd.Parameters.Add(new SqlParameter("@StartDate", Convert.ToDateTime(txtFromDate.Text).ToShortDateString()));
Cmd.Parameters.Add(new SqlParameter("@EndDate", Convert.ToDateTime(txtFromDate.Text).ToShortDateString()));
Cmd.CommandType = CommandType.StoredProcedure;
DA = new SqlDataAdapter(Cmd);

and Stored Procedure Parameters are 

@StartDate DATE = NULL,
@EndDate DATE = NULL

How to pass the data to Stored Procedure.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>