Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
TableAdapter to return only selected columns.
Message
From
30/03/2009 12:59:53
 
 
To
30/03/2009 11:19:04
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
01392118
Message ID:
01392151
Views:
47
Well, I got one approach to get what I wanted, using Linq-To-DataSets. Not sure it is a perfect solution, but it's cool to see how this workis. I suppose this returns an anonymous typed collection, so I'm not sure how that is going to whack me on down the road. But it works for a quick, read only, list to present in the UI:

Basically, you get the regular table that the TableAdatper returns..

then
        public IQueryable GetOpenOrdersByCustomer(string CustNo)
        {

            //Create TableAdapter  
            LMVFPTableAdapters.JobsTableAdapter JobsAdapter = new LMVFPTableAdapters.JobsTableAdapter();

            // Create a DataTable
            LMVFP.JobsDataTable OpenOrders = new LMVFPTableAdapters.JobsTableAdapter().GetActiveJobsByCustNo(CustNo);

            // Linq-To-DataSets (notice the .AsQueryable())
            var OpenOrdersView = from a in OpenOrders.AsQueryable()
                                 select new { a.priority, a.JobNo, a.p_o_num };

            return OpenOrdersView;  // Will suffice as a DataSource for a GridView
        }
>(VS2008) I'm trying to configure a TableAdapter in a Typed DataSet to return only a certain subset of columns from the main schema of the table on which it is based, but it always returns the entire schema (all columns) with blank values in the columns I have omitted.
>
>The TableAdpater has the default Fill and GetData() methods that come from the wizard, which contain every column in the table, which is fine. I then added a new parameterized query method called GetActiveJobsByCustNo(CustNo), and I only included a few columns in the SQL query that I actually want to be in this table view.
>
>But, again, it returns all the columns in the master table schema, with empty values for the columns I omitted.
>
>The reason I am wanting this, is so I can just get a few columns back to use that table view with AutoGenerateColumns in an ASP.NET GridView. With it giving me back EVERY column i nthe schema, my presentation GridView contains way more columns that I want to show th user. And, I want to avoid have to declare the columns in the GridView.
Previous
Reply
Map
View

Click here to load this message in the networking platform