有关代码的一些信息... [英] some information about code...

查看:100
本文介绍了有关代码的一些信息...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void CalenderDRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
    {
        // If the month is CurrentMonth
        if (!e.Day.IsOtherMonth)
        {
            foreach (DataRow dr in ds.Tables[0].Rows) WHAT THIS LINE DO?  IF USE DATATEBLE WHAT IS THE CODE
            {
                if ((dr["EventDate"].ToString() != DBNull.Value.ToString()))WHAT IS DBNull.Value.toString
                {
                    DateTime dtEvent = (DateTime)dr["EventDate"]; WHAT THIS LINE DO?
                    if (dtEvent.Equals(e.Day.Date))
                    {
                        e.Cell.BackColor = Color.PaleVioletRed;
                    }
                }
            }
        }
        //If the month is not CurrentMonth then hide the Dates
        else
        {
            e.Cell.Text = "";
        }
    }

推荐答案

此行遍历数据集第一个表中的所有行.
This line iterates over all the lines in the first table of the dataset.
foreach (DataRow dr in ds.Tables[0].Rows)



此行尝试查看名为 EventDate 的列的值是否为null



This lines attempts to see if the value for the column named EventDate is null

if ((dr["EventDate"].ToString() != DBNull.Value.ToString()))


但操作不正确,应该就是这样):


but it''s done incorrectly, it should be just this):

if ((dr["EventDate"] != DBNull.Value))



这些行将 EventDate 列取出,并将其强制转换为DateTime,并将该值存储在名为dtEvent的局部变量中.



This lines get the EventDate column out and casts it to a DateTime and stores that value in a local variable called dtEvent.

DateTime dtEvent = (DateTime)dr["EventDate"];



希望这会有所帮助,
Fredrik



Hope this helps,
Fredrik


OP写道:

foreach(ds.Tables [0] .Rows中的DataRow dr)这条线吗?如果使用DATATEBLE,则代码是什么

foreach (DataRow dr in ds.Tables[0].Rows) WHAT THIS LINE DO? IF USE DATATEBLE WHAT IS THE CODE


实际上,您已经在这里使用数据表(ds.Tables[0]).代码只是遍历表中的每一行.每行都分配给dr.


Actually, you are already using a data table here(ds.Tables[0]). The code is simply looping through every row in your table. Each row is assigned to dr.

OP写道:

如果((dr ["EventDate"].ToString()!= DBNull.Value.ToString()))什么是DBNull .Value.toString

if ((dr["EventDate"].ToString() != DBNull.Value.ToString()))WHAT IS DBNull.Value.toString


DBNull.Value仅表示数据库中不存在的值. toString方法不是必需的.


DBNull.Value simply represents nonexistent values to the database. The toString method is not necessary.

OP写道:

DateTime dtEvent =(DateTime)dr ["EventDate"];这条线是做什么的?

DateTime dtEvent = (DateTime)dr["EventDate"]; WHAT THIS LINE DO?


如前所述,对于每个循环,数据表中的每一行都分配给dr.对于该特定循环,将dr的"EventDate"列分配给您的dtEvent对象.


As I said a while ago, for every loop, each row from your data table is being assigned to dr. For that specific loop, the "EventDate" column of dr is being assigned to your dtEvent object.


这篇关于有关代码的一些信息...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆