No, there is no need to add any additional references for implementing this property. The CommandCollection already exists in the TableAdapter and holds a collection of System.Data.SqlClient.SqlCommand objects.
I don't know why I am getting a 'Page.aspx' does not contain a definition for 'CommandCollection' and no extension method 'CommandCollection' accepting a first argument of type 'Page.aspx' could be found. (Are you missing a using directive or assembly reference?)
vchany
Member
23 Points
32 Posts
How to get the SelectCommand value of a TableAdapter?
Apr 20, 2012 07:51 AM|LINK
Lets say if we have:
I want to be able to get the SelectCommand generated from the TableAdapter. This seemed possible in VB.Net (see link below) but how can we do this in C#?
http://www.windowsdevelop.com/windows-forms-data-controls-databinding/tableadapter-select-command-26113.shtml
mm10
Contributor
6399 Points
1184 Posts
Re: How to get the SelectCommand value of a TableAdapter?
Apr 20, 2012 08:13 AM|LINK
The TableAdapter hides its dataadapter in a private variable but you can extend it to add a SelectCommand property to return the command:
public string SelectQuery
{
get
{
return this.CommandCollection[0].CommandText;
}
}
vchany
Member
23 Points
32 Posts
Re: How to get the SelectCommand value of a TableAdapter?
Apr 20, 2012 08:24 AM|LINK
Thanks mm10.
Do we need the Microsoft.AnalysisServices.dll for enable this CommandCollection?
http://msdn.microsoft.com/en-us/library/microsoft.analysisservices.commandcollection(v=sql.100).aspx
mm10
Contributor
6399 Points
1184 Posts
Re: How to get the SelectCommand value of a TableAdapter?
Apr 20, 2012 08:32 AM|LINK
No, there is no need to add any additional references for implementing this property. The CommandCollection already exists in the TableAdapter and holds a collection of System.Data.SqlClient.SqlCommand objects.
vchany
Member
23 Points
32 Posts
Re: How to get the SelectCommand value of a TableAdapter?
Apr 20, 2012 08:43 AM|LINK
I don't know why I am getting a 'Page.aspx' does not contain a definition for 'CommandCollection' and no extension method 'CommandCollection' accepting a first argument of type 'Page.aspx' could be found. (Are you missing a using directive or assembly reference?)
mm10
Contributor
6399 Points
1184 Posts
Re: How to get the SelectCommand value of a TableAdapter?
Apr 20, 2012 09:00 AM|LINK
You must implement the property in the TableAdapter class, not on your page.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to get the SelectCommand value of a TableAdapter?
Apr 22, 2012 12:49 AM|LINK
Hello vchany:)
If you want to get the instance of a certain SqlCommand from a certain TableAdapter,you can just fetch from that directly: