One C# Data Grid View displaying on multiple queries input

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aqeel27
    New Member
    • Jan 2013
    • 1

    One C# Data Grid View displaying on multiple queries input

    I have created a generic method which would take the _query string, obj of datagridview, tablename, obj of dataset_ as shown below


    Code:
    private void data(string dgvq, DataGridView dgvw, string sTableNm, DataSet dgset)
            {
                createconn();
                dgset.Clear();
                dAdapter = objADOUI.GetDataAdapter(dgvq, myConn);
                dAdapter.Fill(dgset);
                dgvw.DataSource = dgset.Tables[0].DefaultView;
                this.myConn.Close();
            }

    I am calling this method on different buttons as the are clicked, by passing different parameters. shown below is an example of how its being called.

    Code:
            DataSet dset1 = objADOUI.GetDataSet();
            data(Qdgv, dgvDpnl, "TStudent", dset1);
    Now, the problem is, Its displaying for once, I mean- When `button1` is clicked its displaying the appropriate results.

    But,when `button2` is clicked which has parameters as followed,

    Code:
            DataSet dset2 = objADOUI.GetDataSet();
            data(Qdgv, dgvDpnl, "TStudent", dset2);
    its creating an exception: <br/>
    `"At most one record can be returned by this subquery"` at `data(definitio n)>dAdapter.Fil l(dgset);`

    **Note:**
    Let me tell u the problem is not with the query, since `button1` is also passing the query which has _sub-queries_ too.

    I am aware that the problem is about `unloading` the resources in `datagridview`, `dataset` and `reloading` it.
    But, I have tried a lot and couldn't find the solution.

    Any help would be appreciated.
    Last edited by Meetee; Jan 8 '13, 12:53 PM. Reason: Use code tags <code/> around code
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Your C# code looks fine so I did a bit of research on the web and it looks like this exception is thrown the SQL syntax is not accepted by the database.

    -Frinny
    Last edited by Frinavale; Jan 8 '13, 08:06 PM.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Looks that way to me too. The issue is the query. It's not that you're using subqueries that's causing the issue. It's that the subquery is returning more than one row. Depending on how it's being used, subqueries can be limited to only one row.

      Comment

      Working...