Cannot find table 0 when running calendar

0

Built code to attach employees workdate for a calendar to be marked red when an employee is assigned to a workdate.

But it cannot find table 0 when trying to run the code

System IndexOutOfRangeException HResult 0x80131508 Message Cannot find table 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();
     }
 }
c#
sql
asp.net
datatables
asked on Stack Overflow Aug 13, 2019 by kamekona • edited Aug 13, 2019 by Milo

1 Answer

1

I suppose that the command sqlDataAdapter.Fill(dsMonth); is throwing an exception. You should catch the exception to detect what's wrong.

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

And, you're missing a database connection.

SqlConnection connection = new SqlConnection(connectionString);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
sqlDataAdapter.SelectCommand = new SqlCommand(query, connection);
sqlDataAdapter.Fill(dataset);
answered on Stack Overflow Aug 13, 2019 by Melissa Guzman

User contributions licensed under CC BY-SA 3.0