1

我有一个将执行的 sql 选择脚本,并显示在运行时选择了数据。我遇到的问题是试图让这些数据显示在我的日历控件中。我想通过用户登录的部门更改日历。现在没有任何显示,除非我在其中硬编码部门,否则它不会显示任何数据。

我正在使用 c# asp.net。

这是我正在尝试获取数据的方法

        private DataSet GetData()
    {
        var CurrUser = "a73      ";
        var UsrDepartment = "60      ";

        Account.Login uusr = new Account.Login();
        CurrUser = uusr.User.Identity.Name.ToString().ToUpper();

        ConnectionStringSettingsCollection cssc = ConfigurationManager.ConnectionStrings;

        var sql = "select (substring(status, 1,1)) AS stat1, lastname, firstname, ldate, edate,depdivid, requestid from TIME.employee E inner join TIME.request T on E.EMPID = T.empid where E.depdivid =  @UsrDepartment ";

        using (iDB2Connection conn = new iDB2Connection(GetConnectionString()))
        {
            conn.Open();

            using (iDB2Command cmd = new iDB2Command(sql, conn))
            {
                cmd.DeriveParameters();

                using (iDB2DataAdapter da = new iDB2DataAdapter(cmd))
                {
                    DataSet ds = new DataSet();
                    da.Fill(ds);

                    return ds;
                }
            }
        }
    }

我用这个填写日历:

DataSet ds = GetData();    
foreach (DataRow row in ds.Tables[0].Rows)
                {
                    //need to fill from first to last date
                    string scheduledDate = Convert.ToDateTime(row["ldate"]).ToShortDateString();
                    string endDate = Convert.ToDateTime(row["edate"]).ToShortDateString();

                    e.Cell.Width = 120;
                    e.Cell.Height = 100;

                    Int32 start = 0;
                    Int32 end = 0;

                    start = string.CompareOrdinal(scheduledDate, s);
                    end = string.CompareOrdinal(endDate, s);

                    if ((start <= 0) & (end >= 0) & (!e.Day.IsWeekend))
                    {
                        HyperLink lb = new HyperLink();
                        lb.Text = link + (Int64)row["requestid"] + "' >" + row["lastname"] + "</a>" as String + "(" + row["stat1"] + ")" as String + "<br />";

                        //code to change color of button
                        if (scheduledDate == endDate)
                        {
                            lb.CssClass = "changecolor";
                        }
                        e.Cell.Controls.Add(lb);
                    }
                }

这种方式不会在我的日历中显示任何链接,但如果我让部门有一个值(这不是我想要的),它将显示链接。

4

1 回答 1

1

我认为您需要这样的线路

cmd.Parameters["@UsrDepartment"].Value = myDept
于 2012-10-18T16:17:40.473 回答