Need help accessing Stored Query

Posted on 2014-07-13
Last Modified: 2014-07-14

I'm a beginner.  

My project has a Data Source called On_OrderDataSet which works great.  I'm able to access objects in this data source using code like this:
Dim dtCustomer As DataTable = On_OrderDataSet.Tables("Tbl_Customers")

Open in new window

So, I added a stored parameter-ized query, named Qry_Customers, using the Add option in the .xsd file.  Screenshot shows it.  Problem is that I can't figure out how to use Qry_Customers in my code.  I'd like to do something like:
Dim dtCustomer As DataTable = On_OrderDataSet.Queries("Qry_Customers")

Open in new window

 But it doesn't work.
Screenshot of Data Sources and QueriesTableAdapaterHow do I do fill a DataTable or DataRow object using Qry_Customers?  Code would be helpful.
Question by:SqueezeOJ
    LVL 52

    Accepted Solution

    The QueriesTableAdapter is intended more for executing scalar queries, or performing UPDATE/INSERT/DELETE operations.

    Instead you should be adding your query to the existing Tbl_CustomersTableAdapter. That will then allow you to create a GetDataBy... method, which you can use in the same way as the existing GetData() method, only you'll have the addition of being able to pass a parameter to it.

    Which would then allow you to do something like:
    Dim adap As New DataSet1TableAdapters.CustomerTableAdapter
    Dim table As DataSet1.CustomerDataTable = adap.GetDataByLastName("smith")

    Open in new window


    Author Closing Comment


    I simply recreated the "query" using the same SQL through the Add --> Table Adapter wizard in the .xsd area.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now