Find current day of week in c# ASP.Net
<p><strong>Thank you All This Question is <em>solved</em> Now.</strong></p>

<p>I want to find current day of week in c# ASP.Net like    System.DateTime.Now.DayOfWeek.ToString(); 
This code works well in console application but when I try to store the value of this line in a string in ASP.Net website it returns nothing!
Can anyone help?</p>

<pre><code> StringBuilder message = null;

protected void Page_Load(object sender, EventArgs e)
{
    var dayofweek = System.DateTime.Now.DayOfWeek.ToString();
    String conn = "Data Source=.;Initial Catalog=OCSI;Integrated Security=True";//conne
    SqlConnection sqlconne = new SqlConnection(conn);

    string selectSQL = "SELECT lec FROM schedule WHERE [day]='" + dayofweek +"'";
    SqlCommand cmd = new SqlCommand(selectSQL, sqlconne);
    SqlDataReader reader = null;
    try
    {
        sqlconne.Open();
        reader = cmd.ExecuteReader();
        message = new StringBuider(); 
        while (reader.Read())
        {
            message.Append(reader["lec"].ToString());
           //question what are you using message for ...?
            Label3.Text = dayofweek;
        }
        reader.Close();
    }
    catch (Exception ex)
    {
        Response.Write(ex.Mesage);
    }
    finally
    {
        sqlconne.Close();
        // you neeed to Dispose of all other objects here too
        // StringBuilder Object
        // SqlDataReader Object
        //SqlCommand  Object.. 
        //Look into wrapping your Connection / Command Sql Dataobject around a using() {}
    }
</code></pre>

<p>I want to use current day in where clause SQL Query to get data relevant to current day from database table.</p>

<p>I used var as    protected void Page_Load(object sender, EventArgs e)
    {
        String conn = "Data Source=.;Initial Catalog=OCSI;Integrated Security=True";//conne
        SqlConnection sqlconne = new SqlConnection(conn);</p>

<pre><code>    var testDay = DateTime.Now.DayOfWeek.ToString();

    // string selectSQL = "SELECT lec FROM schedule WHERE [day]='" + dayofweek +"'";
    string selectSQL = string.Format("SELECT lec FROM schedule WHERE [day]= {0}", testDay);
    SqlCommand cmd = new SqlCommand(selectSQL, sqlconne);
    SqlDataReader reader;
    try
    {
        sqlconne.Open();
        reader = cmd.ExecuteReader();

        while (reader.Read())
        {
            message += reader["lec"].ToString();

            Label3.Text = testDay;
        }
        reader.Close();
    }
    catch
    { 
    }
    finally
    {
        sqlconne.Close();
    }
</code></pre>
