Error with Crystal Report in ASP.Net

0
protected void Page_Load(object sender, EventArgs e)
    {
        string cadena = ConfigurationManager.ConnectionStrings["WebBillBarConnectionString1"].ToString();
        SqlConnection con = new SqlConnection(cadena);
        CapaLogica.DataSetBillBar datos = new CapaLogica.DataSetBillBar();

        string sql = "SELECTdbo.factura.fecha, dbo.detalleFactura.numeroFactura, dbo.factura.idCliente,"
        + "dbo.cliente.identificacion, dbo.cliente.nombres, dbo.cliente.apellidos,dbo.detalleFactura.idProducto,"
        + "dbo.detalleFactura.nombre AS producto, dbo.detalleFactura.cantidad,"
        + "dbo.detalleFactura.precio,dbo.detalleFactura.cantidad * dbo.detalleFactura.precio AS subTotal"
        + "FROM dbo.cliente INNER JOIN dbo.factura ON dbo.cliente.idCliente = dbo.factura.idCliente INNER JOIN"
        + "dbo.detalleFactura ON dbo.factura.numeroFactura = dbo.detalleFactura.numeroFactura";
        SqlDataAdapter adapter = new SqlDataAdapter(sql, con);

        adapter.Fill(datos.ReporteFactura);

        CrystalReporteFacturas reporte = new CrystalReporteFacturas();
        CrystalReportViewer1.ReportSource = reporte;
    }
}

I have those lines of code and I get this error:

  

System.Data.SqlClient.SqlException: Incorrect syntax near ','.

     

Line 22: SqlDataAdapter adapter = new SqlDataAdapter (sql,   with);

I have already reviewed and revised and I do not give with the joke,

Can someone please help me?

    
asked by jesus de la hoz 05.12.2018 в 21:33
source

1 answer

0

Try giving space to each end of chain, like this:

string sql = "SELECT dbo.factura.fecha, dbo.detalleFactura.numeroFactura, dbo.factura.idCliente, "
+ "dbo.cliente.identificacion, dbo.cliente.nombres, dbo.cliente.apellidos,dbo.detalleFactura.idProducto, "
+ "dbo.detalleFactura.nombre AS producto, dbo.detalleFactura.cantidad, "
+ "dbo.detalleFactura.precio,dbo.detalleFactura.cantidad * dbo.detalleFactura.precio AS subTotal "
+ "FROM dbo.cliente INNER JOIN dbo.factura ON dbo.cliente.idCliente = dbo.factura.idCliente INNER JOIN "
+ "dbo.detalleFactura ON dbo.factura.numeroFactura = dbo.detalleFactura.numeroFactura";

This way, when you finish concatenating the chains, you do not paste the termination of one with the initialization of the other.

Another way to create the chain without having to use ( + ), would be putting a ( @ ) when creating the chain, like this:

string sql = @"
    SELECT
        dbo.factura.fecha, 
        dbo.detalleFactura.numeroFactura,
        dbo.factura.idCliente,
        dbo.cliente.identificacion,
        dbo.cliente.nombres,
        dbo.cliente.apellidos,
        dbo.detalleFactura.idProducto,
        dbo.detalleFactura.nombre AS producto,
        dbo.detalleFactura.cantidad,
        dbo.detalleFactura.precio,
        dbo.detalleFactura.cantidad * dbo.detalleFactura.precio AS subTotal
    FROM
        dbo.cliente
    INNER JOIN
        dbo.factura ON dbo.cliente.idCliente = dbo.factura.idCliente
    INNER JOIN
        dbo.detalleFactura ON dbo.factura.numeroFactura = dbo.detalleFactura.numeroFactura
    ";

Note:
There is never another directly execute the query in the database engine, this way we always avoid finger errors.

    
answered by 05.12.2018 в 21:39