【发布时间】:2019-08-13 13:34:13
【问题描述】:
用于附加员工工作日期的内置代码,以便在将员工分配到工作日期时将日历标记为红色。
但运行代码时找不到表0
System IndexOutOfRangeException HResult 0x80131508 消息找不到 表 0。
public partial class Schema: System.Web.UI.Page {
protected DataSet dsDays;
protected void Page_Load(object sender, EventArgs e) {
Calendar1.VisibleDate = DateTime.Today;
FillDayDataset();
}
protected void FillDayDataset() {
dsDays = GetCurrentMonthData();
}
protected DataSet GetCurrentMonthData() {
DataSet dsMonth = new DataSet();
String query;
query = "SELECT * FROM Schema WHERE EmployeeId = @EmployeeId";
Session["EmployeeId"]));
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(dbCommand);
try {
sqlDataAdapter.Fill(dsMonth);
} catch {}
return dsMonth;
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e) {
if (dsDays != null) {
if (Session["EmployeeId"] != null) {
foreach(DataRow dr in dsDays.Tables[0].Rows) {
if ((DateTime) dr["Arbetsdatum"] == e.Day.Date) {
e.Cell.BackColor = System.Drawing.Color.Pink;
}
}
}
}
}
protected void Calendar1_VisibleMonthChanged(object sender,
MonthChangedEventArgs e) {
FillDayDataset();
}
}
【问题讨论】:
-
SqlConnection 和 SqlCommand 在哪里?你在创建一个 SqlCommand 吗?
-
是的,我正在创建一个 sql 命令,但无法在此处发布
标签: c# sql asp.net datatables