DataTable timeTable = new DataTable(); DataColumn colSubject = new DataColumn("Subject Name"); DataColumn colClass = new DataColumn("Class"); DataColumn colTeacher = new DataColumn("Lecturer"); DataColumn colStartTime = new DataColumn("Start"); DataColumn colEndTime = new DataColumn("End"); colSubject.DataType = System.Type.GetType("System.String"); colClass.DataType = System.Type.GetType("System.String"); colTeacher.DataType = System.Type.GetType("System.String"); colStartTime.DataType = System.Type.GetType("System.String"); colEndTime.DataType = System.Type.GetType("System.String"); timeTable.Columns.Add(colSubject); timeTable.Columns.Add(colClass); timeTable.Columns.Add(colTeacher); timeTable.Columns.Add(colStartTime); timeTable.Columns.Add(colEndTime); int numOfRows = 0; SqlDataReader read = null; try { conn.Open(); read = getTimetable.ExecuteReader(); if (read.HasRows) { while (read.Read()) { if (numOfRows < 3) { DataRow row = timeTable.NewRow(); row[colSubject] = read["subject_name"].ToString(); row[colClass] = read["resource_name_number"].ToString(); row[colTeacher] = read["userDetail_name"].ToString(); row[colStartTime] = read["timeSlot_startTime"].ToString(); row[colEndTime] = read["timeSlot_endTime"].ToString(); timeTable.Rows.Add(row); numOfRows++; } } gridTimeTable.DataSource = timeTable; gridTimeTable.DataBind(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)