By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,902 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,902 IT Pros & Developers. It's quick & easy.

One C# Data Grid View displaying on multiple queries input

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


Expand|Select|Wrap|Line Numbers
  1. private void data(string dgvq, DataGridView dgvw, string sTableNm, DataSet dgset)
  2.         {
  3.             createconn();
  4.             dgset.Clear();
  5.             dAdapter = objADOUI.GetDataAdapter(dgvq, myConn);
  6.             dAdapter.Fill(dgset);
  7.             dgvw.DataSource = dgset.Tables[0].DefaultView;
  8.             this.myConn.Close();
  9.         }
  10.  

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.

Expand|Select|Wrap|Line Numbers
  1.         DataSet dset1 = objADOUI.GetDataSet();
  2.         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,

Expand|Select|Wrap|Line Numbers
  1.         DataSet dset2 = objADOUI.GetDataSet();
  2.         data(Qdgv, dgvDpnl, "TStudent", dset2);
its creating an exception: <br/>
`"At most one record can be returned by this subquery"` at `data(definition)>dAdapter.Fill(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.
Jan 8 '13 #1
Share this Question
Share on Google+
2 Replies


Frinavale
Expert Mod 5K+
P: 9,731
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
Jan 8 '13 #2

Rabbit
Expert Mod 10K+
P: 12,359
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.
Jan 8 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.