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();
}
}
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);
User contributions licensed under CC BY-SA 3.0