Category Archives: adapter

Filling DataTable From Access Database in C#

i am filling DataTable form access database. when execution comes to "adapter.Fill(table)" it jumps to mdi form and shows me the empty form. I don't know what to do? Below is my code. Thanks in Advance.

private void Attendence_Report_Load(object sender, EventArgs e)
        {
            OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\farman C# project\next.accdb");
            OleDbCommand com = new OleDbCommand();
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            DataTable table = new System.Data.DataTable();

            com.CommandText = "SELECT Student.SName, Student.FatherName, Class.ClassName AS Class, `Section`.SectoinName AS `Section`, Attendance.Attendance, Attendance.Date AS `Date` FROM " +
                "((Attendance INNER JOIN Student ON Attendance.StudentID = Student.ID) INNER JOIN Class ON Attendance.ClassID = Class.ID) INNER JOIN `Section` ON Attendance.SectionID = `Section`.ID";

            com.Connection = con;
            con.Open();
            adapter.SelectCommand = com;
            adapter.Fill(table);
            con.Close();
            reportViewer1.LocalReport.ReportEmbeddedResource = "Attendence.Attendence_Report.rdlc";
            ReportDataSource source = new ReportDataSource("DataSet1", table);
            reportViewer1.LocalReport.DataSources.Clear();
            reportViewer1.LocalReport.DataSources.Add(source);
            reportViewer1.RefreshReport();

        }