English 中文(简体)
每周在c# ASP学习。 净额
原标题:Find current day of week in c# ASP.Net
  • 时间:2012-01-13 19:30:49
  •  标签:
  • c#
  • asp.net

我想找到目前这一周日。 净额:

System.DateTime.Now.DayOfWeek.ToString(); 

该法典在奥连应用中运作良好,但当我试图将这一条线的价值储存在伙伴关系中时。 网上网站没有收效。

谁能帮助?

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() {}
    }

我想利用目前这个日子,在那个日子里,“Q”条款从数据库桌上获取与当前日相关的数据。

我使用了var。

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

    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();
    }
最佳回答

如果在你删除条款时一切事事事事事事事事,那么该条款就改变了。

   string selectSQL = string.Format("SELECT lec FROM schedule WHERE dbo.schedule.day = {0} ", testDay);

I would also change the name of the field day to something like DayName or something if day is a Reserved word don t use it.. look at this link for Reserved Words in SQL Reserved SQL Words

问题回答

它对我课以罚款。

enter image description here

Wep page is the value defined as a public , static, or property..

页: 1

var testDay = DateTime.Now.DayOfWeek.ToString();

the results will = "Friday";

并试图改变你对此的描述

string selectSQL = 
   string.Format("SELECT lec FROM schedule WHERE [day]= {0}", dayofweek);

ger价值(系统为0天)=

int day = (int)DateTime.Now.DayOfWeek;




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签