【问题标题】:Cannot find table 0 when running calendar运行日历时找不到表 0
【发布时间】: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


【解决方案1】:

我认为命令sqlDataAdapter.Fill(dsMonth); 正在引发异常。您应该捕获异常以检测问题所在。

catch (Exception e)
    {
        Console.WriteLine("{0} Exception caught.", e);
    }

而且,您缺少数据库连接。

SqlConnection connection = new SqlConnection(connectionString);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
sqlDataAdapter.SelectCommand = new SqlCommand(query, connection);
sqlDataAdapter.Fill(dataset);

【讨论】:

    猜你喜欢
    • 2013-06-27
    • 1970-01-01
    • 2015-05-22
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    • 2018-01-22
    • 1970-01-01
    相关资源
    最近更新 更多