我有一个sql select脚本,它将执行并显示运行时正在选择数据。我遇到的问题是尝试将数据显示在我的日历控件中。我想根据用户登录的部门更改日历。现在没有任何显示,除非我对其中的部门进行硬编码,否则不会显示任何数据。
我正在使用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);
}
}
这种方式在我的日历中不显示任何链接,但如果我让部门有一个值(这不是我想要的),它将显示链接。
答案 0 :(得分:1)
我认为你需要这样一行
cmd.Parameters["@UsrDepartment"].Value = myDept