I would like to ask a question about returning the column value(s) returned by stored procedure in c#. I have created the code but somehow I encountered an error saying:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

Here is my code

      public void Display(string pdesc, string psdesc, string psize, string category, ListView lv)
            queryString = "execute dbo.sp_RunningBalance @desc, @sdesc, @cat, @size";
            SqlCommand cmd = new SqlCommand(queryString, cn.con);
            cmd.Parameters.AddWithValue("@cat", category);
            cmd.Parameters.AddWithValue("@desc", pdesc);
            cmd.Parameters.AddWithValue("@sdesc", psdesc);
            cmd.Parameters.AddWithValue("@size", psize);
            SqlDataReader rd = cmd.ExecuteReader();

            while (rd.Read())
                var ctrl_listviewItem = new ListViewItem();
                ctrl_listviewItem.Text = rd["EntDT"].ToString();
                ctrl_listviewItem.SubItems.Add(rd["InventoryID"].ToString()); // Inventory ID
                ctrl_listviewItem.SubItems.Add(rd["Qty"].ToString()); // Qty
                ctrl_listviewItem.SubItems.Add(rd["UOM"].ToString()); // uom
                ctrl_listviewItem.SubItems.Add(rd["Balance"].ToString()); // balance
                ctrl_listviewItem.SubItems.Add(rd["Status"].ToString()); // status
                ctrl_listviewItem.SubItems.Add(rd["Remarks"].ToString()); // remarks


Please help me with the error

Thank you in advance :)

I have a feeling the problem is in the Stored Proc and not your code. Might be useful to share that

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.