C#中的窗口表单应用程序中的总和未处理无效的操作异常

时间:2018-08-02 03:21:20

标签: c# asp.net sql-server

string queryn2 = null;
queryn2 = "SELECT  SUM (product_complete)  AS productcomplete,SUM(product_incomplete)  AS productincomplete,SUM(amount) AS amount  from intern_planuser where orderitem = '" + textBox15.Text + "' and vendername = '" + vendernamelist[0] + "'";

SqlCommand cmdn3 = new SqlCommand(queryn2, con5);
SqlDataReader drn3 = cmdn3.ExecuteReader();

d1 = 0;

while (drn3.Read())
{
    sumproductcomplete[d1] = drn3.GetInt32(0);
    sumproductcompletet[d1] = Convert.ToString(sumproductcompletet[d1]);
    sumproductincomplete[d1] = drn3.GetInt32(1);
    sumproductincompletet[d1] = Convert.ToString(sumproductincompletet[d1]);

    sumproductamount[d1] = drn3.GetInt32(2);
    d1++;
    // productincomplete = Convert.ToInt32(drn2["productincomplete"]);
}

drn3.Close();

sumproductlost[0] = sumproductamount[0] - sumproductcomplete[0] - sumproductincomplete[0];
sumproductlostt[0] = Convert.ToString(sumproductlostt);

label14.Text = sumproductcompletet[0];
label68.Text = sumproductincompletet[0];
label42.Text = sumproductlostt[0];

使用sum语句时出现错误。我已经尝试从SQL查询,它可以工作,但是当我执行代码时,出现错误

  

未处理无效的操作异常。

如何解决此错误?

0 个答案:

没有答案