我正在尝试生成报告,并且我想从访问数据库中传递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);
}
}
}