如何将dataGridView值传递给reportViewer?

时间:2017-03-16 03:40:16

标签: c# datagridview report

我正在尝试生成报告,并且我想从访问数据库中传递datagridview的值。这是从访问datagridview输入值的方法,我想在reportviewer中传输它。

private void loading()
{
     {
         try
         {
             connection.Open();
             OleDbCommand command = new OleDbCommand();
             command.Connection = connection;
             string query = "SELECT [EmployeeID],[Firstname],[Middlename],[Lastname],[InDate],[InTime],[OutTime],[HoursWorked] FROM TimeinTimeout WHERE InDate between @1 AND @2";
             command.Parameters.AddWithValue("@1", dateTimePicker1.Value.ToShortDateString());
             command.Parameters.AddWithValue("@2", dateTimePicker2.Value.ToShortDateString());
             command.CommandText = query;
             OleDbDataAdapter da = new OleDbDataAdapter(command);
             DataTable dt = new DataTable();
             da.Fill(dt);
             dataGridView1.DataSource = dt;
             dataGridView1.AutoGenerateColumns = false;
             dataGridView1.Update();
             dataGridView1.Refresh();
             dataGridView1.Columns["InTime"].DefaultCellStyle.Format = "hh:mm tt";
             dataGridView1.Columns["OutTime"].DefaultCellStyle.Format = "hh:mm tt";
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
     }
}

0 个答案:

没有答案