如何在文本框中获取sql(sum)查询的值?

时间:2015-05-05 07:36:44

标签: c# sql sql-server winforms

我想分别在两个字符串中添加2行的总和,请帮忙

我的功能编码所有参数都很好但仍然出错

public void temporderentry(SqlConnection conn,SqlCommand comd)
    {
        string sql = "select SUM(productQuaintyInOrder)  ,SUM(cost)  from OrderProduct where orderID = " + oid; //oid is defined
        if (conn.State != ConnectionState.Open)
        {
            conn.Open();
        }

        comd = new SqlCommand(sql, conn);
        SqlDataReader dr = comd.ExecuteReader();
        while (dr.HasRows)
        {
            cart = Convert.ToInt32(dr[0]);
            totalpayment = Convert.ToInt32(dr[1]);
        }
    }

这里的错误

+       base    {"Invalid attempt to read when no data is present."}    System.Exception {System.InvalidOperationException}

0 个答案:

没有答案