0

I have this code:

private void GenerarTicket(int prmFOLIO)
        {
            try
            {
                string Ticket = "Nombre de la tienda: UAMCAV\n" +
                    "RFC:XXXXXX\n" +
                    "------------------------------\n" +
                    "ARTICULO   CANT   PRECIO   TOTAL\n" +
                    "------------------------------\n";
                string varSQL = "SELECT Detalle_Ventas.folio, Detalle_Ventas.id_articulo, Detalle_Ventas.cantidad, Detalle_Ventas.p_unitario, Detalle_Ventas.iva*Detalle_Ventas.p_unitario AS iva, Detalle_Ventas.cantidad*Detalle_Ventas.p_unitario AS total, articulos.desc_producto, Ventas.user_login, LEFT(Ventas.fecha,10) AS fecha " + " FROM Ventas INNER JOIN (articulos INNER JOIN Detalle_Ventas ON articulos.id_articulo=Detalle_Ventas.id_articulo) ON Ventas.folio=Detalle_Ventas.folio WHERE Ventas.folio=" + prmFOLIO + "";

                string DetalleTicket = "";
                double varGranTotal = 0;
                OleDbConnection cnnTicket =new OleDbConnection(Clases.clsMain.CnnStr);
                cnnTicket.Open();
                OleDbCommand cmdTicket =new OleDbCommand(varSQL, cnnTicket);
                OleDbDataReader drTicket;
                **drTicket = cmdTicket.ExecuteReader();**
                while (drTicket.Read())
                {
                    DetalleTicket +=
                        drTicket["desc_producto"].ToString() + "   " +
                        drTicket["cantidad"].ToString() + "   " +
                        String.Format("{0:C}",
                        drTicket["p_unitario"]) + "   " +
                        String.Format("{0:C}",
                        drTicket["total"]) + "\n";
                    varGranTotal += (double)drTicket["total"];
                }
                DetalleTicket +=
                    "------------------------------\n" +
                    "TOTAL: " + String.Format("{0:C}",
                    varGranTotal);
                Ticket += DetalleTicket;
                mPrintDocument _mPrintDocument = new mPrintDocument(Ticket);
                _mPrintDocument.PrintPreview();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

I modified the bold section many times because there is always throwing a strange exception for me, like a circular reference in the alias "desc_producto", I use a .dll created by me to generate a shopping ticket, but there is no way to fix this exception! Can you help me? By the way, that's the name of the item in the data base.

j08691
  • 204,283
  • 31
  • 260
  • 272
  • "circular reference in the alias desc_producto" typically means you just need to pick a field alias that is not the same as your field name. If you change `as desc_producto` to `as desc_producto2` and `drTicket["desc_producto"]` to `drTicket["desc_producto2"]`, does that fix your problem?? – Mark Balhoff Feb 24 '15 at 04:22
  • Not worked, It says there's not specific values to some stablished parameters! – SdwAlchmist Feb 24 '15 at 04:30
  • Ok! I made it, but, this piece of code suppose to print a ticket but none of those items shows in the preview! You have an idea? I'm going to modify the code! – SdwAlchmist Feb 24 '15 at 08:35

1 Answers1

0

Cause of that exception => Circular Reference Caused by Alias

The alias, or label, of a calculated field cannot be identical to any of the field names used to calculate the field.

change query to below.

string varSQL =
                "**SELECT LEFT(desc_producto,10) as desc_product_o,**" +
                " cantidad,p_unitario,total" +
                " FROM Ventas WHERE Folio=" + prmFOLIO + "";

It would have worked.

Here is Microsoft support link for more detail.

Update

Also need to change code inside while loop.

 while (drTicket.Read())
 {
     DetalleTicket +=
     drTicket["desc_product_o"].ToString() + "   " +
     drTicket["cantidad"].ToString() + "   " +
     String.Format("{0:C}",
     drTicket["p_unitario"]) + "   " +
     String.Format("{0:C}",
     drTicket["total"]) + "\n";
     varGranTotal += (double)drTicket["total"];
 }
Jenish Rabadiya
  • 6,708
  • 6
  • 33
  • 62
  • Yep! Still doesn't work, with the "**" it says "invalid instruction", without the "**" it says there's not specific values to some stablished parameters, in the table Ventas, I don't have an item desc_producto because I don't need it, It is in the table articulos. Sorry if my english is not good! – SdwAlchmist Feb 24 '15 at 06:19