Reporting

2

Good Night, it must be simple, but I'm breaking my head and it's not going.

I made a report of the college project "Pieces in Stock" and it is working perfectly. When I ran the tests the DateTime with the time was reset, then I set the time and my Form is working perfectly.

However, only dates that are zeroed ( 00:00:00 ) appear in the report, but when it has a specified time ( 18:35:06 ) does not show.

Following the images and code, I'm doing the project in layers, but I have no idea how to do the report by taking the DAO layer, so I made it in the View layer. Is it wrong to do so?

code

privatevoidbtnGerar_Click(objectsender,EventArgse){SqlCommandcmd=newSqlCommand();SqlDataAdapterda=newSqlDataAdapter();DataSetdsum=newDataSet();DataTableoTable=newDataTable();StringstrReportPath="";
        try
        {
            strReportPath = @"Report1.rdlc";
            reportViewer1.LocalReport.ReportPath = strReportPath;
            SqlConnection conn = new SqlConnection(@"Data Source=DENILSON-PC;Initial Catalog=dbSistEstoqueEmp;Integrated Security=True");
            cmd.Connection = conn;
            cmd.CommandText = "SELECT * FROM tbEntradaEstoque WHERE data_ent = @dataEnt";
            cmd.CommandType = CommandType.Text;
            conn.Open();
            cmd.Parameters.Add("dataEnt", SqlDbType.DateTime).Value = Convert.ToDateTime(maskDataInicial.Text);

            SqlDataReader oDataReader = cmd.ExecuteReader();
            oTable.Load(oDataReader);
            ReportDataSource myReportDataSource = new ReportDataSource("DataSet1", oTable);
            reportViewer1.Clear();
            reportViewer1.LocalReport.DataSources[0] = myReportDataSource;
            reportViewer1.RefreshReport();


        }
        catch (Exception ex)
        {

            MessageBox.Show(ex.Message);
        }
    }

thanks bruno it worked out .date in my parameter.

How am I doing in 4 layers is it wrong to do the reports in the View layer?

Thank you

    
asked by anonymous 04.05.2015 / 03:38

1 answer

2

The problem here is statement:

cmd.CommandText = "SELECT * FROM tbEntradaEstoque WHERE CONVERT(DATE, data_ent) = @dataEnt";
(...)
cmd.Parameters.Add("dataEnt", SqlDbType.DateTime).Value = Convert.ToDateTime(maskDataInicial.Text);

By implying the format of the date in the database is datetime(datetime2) . Your statement converts a date in the format dd/mm/yyyy to the format yyyy/mm/dd hh:mm:ss[.fração de segundos] , with the particularity that the hh:mm:ss[fração de segundos] component is always 00:00:00 000

Your SQL statement to get the results in the database is as follows:

cmd.CommandText = "SELECT * FROM tbEntradaEstoque WHERE data_ent = @dataEnt";

So it will only return the records that have in the database 00:00:00 000 in the component hh:mm:ss[.fração de segundos] ,

One solution is to change your statement to

cmd.CommandText = "SELECT * FROM tbEntradaEstoque WHERE CONVERT(DATE, data_ent) = @dataEnt";

and

cmd.Parameters.Add("dataEnt", SqlDbType.DateTime).Value = Convert.ToDateTime(maskDataInicial.Text).Date;

(Or simply convert directly the String maskDataInicial.Text to the Date format (without hh: mm: ss)

    
04.05.2015 / 10:35