0

我有这个代码:

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);
            }
        }

我多次修改了粗体部分,因为总是给我抛出一个奇怪的异常,比如别名“desc_producto”中的循环引用,我使用我创建的.dll来生成购物票,但是没有办法修复这个例外!你能帮助我吗?顺便说一句,这是数据库中项目的名称。

4

1 回答 1

0

该异常的原因=>别名引起的循环引用

计算字段的别名或标签不能与用于计算该字段的任何字段名称相同。

将查询更改为以下。

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

它会奏效的。

这是 Microsoft 支持链接以获取更多详细信息。

更新

还需要在while循环中更改代码。

 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"];
 }
于 2015-02-24T04:22:04.757 回答