Now i have Converted the Date in to String the SQL Query. I am selecting only 10 characters from the Date Column.
Namespace
using System.Configuration;
using System.Data.SqlClient;
using System.Globalization;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string constr = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT message FROM tblMessages WHERE CONVERT(VARCHAR(10),DisplayDate,21) = @DisplayDate", con))
{
cmd.Parameters.AddWithValue("@DisplayDate", DateTime.Now.ToString("yyyy-MM-dd", new CultureInfo("en-gb")));
con.Open();
object message = cmd.ExecuteScalar();
con.Close();
if (message != null)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + message.ToString() + "')", true);
}
}
}
}
}