SQL Server subqueries Populate the DataSet Times 500 Internal error resolution

Source: Internet
Author: User
Tags try catch visual studio 2010

The operating environment is visual Studio 2010, and the database is SQL Server 2008.

Execute the following SQL statement

SELECT Count (CollectionID) Collectionnumber,Count(LName) plantnumber    from (SELECTDISTINCT Subsiteid, Subsitetitle, CollectionID, LName, CName                from where lname='Agave sisalana'Group  by Subsiteid, Subsitetitle

Running normally in Enterprise Manager, you can query the results, but in the program you always prompt for 500 internal errors. The following is the C # code:

1 New SqlConnection (strconn); 2 New SqlCommand (SQL, conn); 3 Conn. Open (); 4 New SqlDataAdapter (cmd); 5 " DS ");  // there 's an error. 6 Conn. Close ();

No exception is caught on code try catch.


Workaround: Simply add an alias to the inner subquery.

SELECT  Count (Q.collectionid) Collectionnumber,Count(q.lname) plantnumber     from (SELECTDISTINCT  Subsiteid, Subsitetitle, CollectionID, LName, CName             fromwhere LName=  'Agave sisalana') qGroup by Subsiteid, Subsitetitle

SQL Server subqueries Populate the DataSet Times 500 Internal error resolution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.