PC Review


Reply
Thread Tools Rate Thread

Accessing query command

 
 
John
Guest
Posts: n/a
 
      28th Jan 2009
Hi

I have a strongly typed dataset in my winform app. I need to access a
specific command of a specific query of a specific table adapter of a
specific table in the dataset in my code in one of the forms? How can I
achieve this?

I need something like this;

x = MyDataset.MyTable.MyTableTableAdapter.MyQueryOne.CommandText

Thanks

Regards


 
Reply With Quote
 
 
 
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      28th Jan 2009
John,

This is one of the main reasons why I don't like the TableAdapter.

Cor


"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
>
> I have a strongly typed dataset in my winform app. I need to access a
> specific command of a specific query of a specific table adapter of a
> specific table in the dataset in my code in one of the forms? How can I
> achieve this?
>
> I need something like this;
>
> x = MyDataset.MyTable.MyTableTableAdapter.MyQueryOne.CommandText
>
> Thanks
>
> Regards
>


 
Reply With Quote
 
John
Guest
Posts: n/a
 
      28th Jan 2009
There is no way to achieve this? How does one change the existing SQL?

"Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> John,
>
> This is one of the main reasons why I don't like the TableAdapter.
>
> Cor
>
>
> "John" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi
>>
>> I have a strongly typed dataset in my winform app. I need to access a
>> specific command of a specific query of a specific table adapter of a
>> specific table in the dataset in my code in one of the forms? How can I
>> achieve this?
>>
>> I need something like this;
>>
>> x = MyDataset.MyTable.MyTableTableAdapter.MyQueryOne.CommandText
>>
>> Thanks
>>
>> Regards
>>

>



 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      28th Jan 2009
John,'

I would use simple a DataAdapter with the DataTable, the table adapter is
AFAIK nothing more then an overloaded DataAdapter inside the DataSet.

(The latter is for the fill in fact a smart datareader, before William gives
a reply).

Cor

"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> There is no way to achieve this? How does one change the existing SQL?
>
> "Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> John,
>>
>> This is one of the main reasons why I don't like the TableAdapter.
>>
>> Cor
>>
>>
>> "John" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi
>>>
>>> I have a strongly typed dataset in my winform app. I need to access a
>>> specific command of a specific query of a specific table adapter of a
>>> specific table in the dataset in my code in one of the forms? How can I
>>> achieve this?
>>>
>>> I need something like this;
>>>
>>> x = MyDataset.MyTable.MyTableTableAdapter.MyQueryOne.CommandText
>>>
>>> Thanks
>>>
>>> Regards
>>>

>>

>
>


 
Reply With Quote
 
miher
Guest
Posts: n/a
 
      28th Jan 2009


> There is no way to achieve this? How does one change the existing SQL?

By the designer You can change the sql.


>>> I need something like this;
>>>
>>> x = MyDataset.MyTable.MyTableTableAdapter.MyQueryOne.CommandText
>>>



The commands are hold in the TableAdapters CommandCollection array. This is
protected so You cant really get it from outside. If You really want to do
this, expose the commands by for example a public property, since the
tableadapter is generated as a partial class.
To do this:
- go to Your dataset design view
- select the tableadapter/right click -> view code
- in the generated skeleton place a property to expose the command texts,
for example
public string MyCommand
{
get { return CommandCollection[0].CommandText; }
}


-Zsolt

 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      28th Jan 2009
Miher,

A way that can be done, however the change that I forget this as I
regenerate the dataset is 100,
This happens of course not to you. However, I don't think I am not the only
one where this happens.

Cor


"miher" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
>
>> There is no way to achieve this? How does one change the existing SQL?

> By the designer You can change the sql.
>
>
>>>> I need something like this;
>>>>
>>>> x = MyDataset.MyTable.MyTableTableAdapter.MyQueryOne.CommandText
>>>>

>
>
> The commands are hold in the TableAdapters CommandCollection array. This
> is protected so You cant really get it from outside. If You really want to
> do this, expose the commands by for example a public property, since the
> tableadapter is generated as a partial class.
> To do this:
> - go to Your dataset design view
> - select the tableadapter/right click -> view code
> - in the generated skeleton place a property to expose the command texts,
> for example
> public string MyCommand
> {
> get { return CommandCollection[0].CommandText; }
> }
>
>
> -Zsolt


 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      28th Jan 2009
change has to be chance, the times that I make this mistake is almost as
well 100%

Cor

"Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Miher,
>
> A way that can be done, however the change that I forget this as I
> regenerate the dataset is 100,
> This happens of course not to you. However, I don't think I am not the
> only one where this happens.
>
> Cor
>
>
> "miher" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>
>>
>>> There is no way to achieve this? How does one change the existing SQL?

>> By the designer You can change the sql.
>>
>>
>>>>> I need something like this;
>>>>>
>>>>> x = MyDataset.MyTable.MyTableTableAdapter.MyQueryOne.CommandText
>>>>>

>>
>>
>> The commands are hold in the TableAdapters CommandCollection array. This
>> is protected so You cant really get it from outside. If You really want
>> to do this, expose the commands by for example a public property, since
>> the tableadapter is generated as a partial class.
>> To do this:
>> - go to Your dataset design view
>> - select the tableadapter/right click -> view code
>> - in the generated skeleton place a property to expose the command texts,
>> for example
>> public string MyCommand
>> {
>> get { return CommandCollection[0].CommandText; }
>> }
>>
>>
>> -Zsolt

>


 
Reply With Quote
 
William Vaughn \(MVP\)
Guest
Posts: n/a
 
      28th Jan 2009
As Cor said (I think), even if you could change it, the results would be
less than desirable. Consider that the entire class is generated code based
on the CommandText. Unlike an untyped DataSet, the strongly typed
TableAdapter assumes that the SQL used to fetch the rowset is unchanged. If
you simply want to change the WHERE clause, then you need to create another
Fill method (using the TableAdapter UI) that returns a different set of rows
but with the same signature (column schema).

hth

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
http://betav.com http://betav.com/blog/billva
____________________________________________________________________________________________



"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> There is no way to achieve this? How does one change the existing SQL?
>
> "Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> John,
>>
>> This is one of the main reasons why I don't like the TableAdapter.
>>
>> Cor
>>
>>
>> "John" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi
>>>
>>> I have a strongly typed dataset in my winform app. I need to access a
>>> specific command of a specific query of a specific table adapter of a
>>> specific table in the dataset in my code in one of the forms? How can I
>>> achieve this?
>>>
>>> I need something like this;
>>>
>>> x = MyDataset.MyTable.MyTableTableAdapter.MyQueryOne.CommandText
>>>
>>> Thanks
>>>
>>> Regards
>>>

>>

>
>

 
Reply With Quote
 
miher
Guest
Posts: n/a
 
      28th Jan 2009
Hi,

I hope i understood Your post right. I suppose i might have been unclear,
but the code i posted should be put into <dataset>.cs file, so it wont be
overwritten when the dataset is regenerated. As i know when one selects the
tableadapter in the designer and selects "view code", it will open the
<dataset>.cs file, maybe i should have explicitly mentioned that. I would
like to point out that You are right, this code can be easily broken, if
someone wants to.

Also please note that what i posted here is only a tip, i never mentioned
that this is the best possible solution, as always every other solution is
welcomed.

Please let me know if i misunderstood Your post, or if i know something
wrong so i can learn from it.

-Zsolt

"Cor Ligthert[MVP]" <(E-Mail Removed)> az alábbiakat írta a
következo üzenetben news:(E-Mail Removed)...
> change has to be chance, the times that I make this mistake is almost as
> well 100%
>
> Cor
>
> "Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Miher,
>>
>> A way that can be done, however the change that I forget this as I
>> regenerate the dataset is 100,
>> This happens of course not to you. However, I don't think I am not the
>> only one where this happens.
>>
>> Cor
>>
>>
>> "miher" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>
>>>
>>>> There is no way to achieve this? How does one change the existing SQL?
>>> By the designer You can change the sql.
>>>
>>>
>>>>>> I need something like this;
>>>>>>
>>>>>> x = MyDataset.MyTable.MyTableTableAdapter.MyQueryOne.CommandText
>>>>>>
>>>
>>>
>>> The commands are hold in the TableAdapters CommandCollection array. This
>>> is protected so You cant really get it from outside. If You really want
>>> to do this, expose the commands by for example a public property, since
>>> the tableadapter is generated as a partial class.
>>> To do this:
>>> - go to Your dataset design view
>>> - select the tableadapter/right click -> view code
>>> - in the generated skeleton place a property to expose the command
>>> texts, for example
>>> public string MyCommand
>>> {
>>> get { return CommandCollection[0].CommandText; }
>>> }
>>>
>>>
>>> -Zsolt

>>

>

 
Reply With Quote
 
John
Guest
Posts: n/a
 
      29th Jan 2009
Hi Bill

I only read one record at a time which has advantage of scalability among
other therefore can not use sorting on bound controls.

Thanks

Regards

"William Vaughn (MVP)" <(E-Mail Removed)> wrote in message
news:F3DD4540-DDD1-4A45-90B1-(E-Mail Removed)...
> As Cor said (I think), even if you could change it, the results would be
> less than desirable. Consider that the entire class is generated code
> based on the CommandText. Unlike an untyped DataSet, the strongly typed
> TableAdapter assumes that the SQL used to fetch the rowset is unchanged.
> If you simply want to change the WHERE clause, then you need to create
> another Fill method (using the TableAdapter UI) that returns a different
> set of rows but with the same signature (column schema).
>
> hth
>
> --
> __________________________________________________________________________
> William R. Vaughn
> President and Founder Beta V Corporation
> Author, Mentor, Dad, Grandpa
> Microsoft MVP
> (425) 556-9205 (Pacific time)
> Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
> http://betav.com http://betav.com/blog/billva
> ____________________________________________________________________________________________
>
>
>
> "John" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> There is no way to achieve this? How does one change the existing SQL?
>>
>> "Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> John,
>>>
>>> This is one of the main reasons why I don't like the TableAdapter.
>>>
>>> Cor
>>>
>>>
>>> "John" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> Hi
>>>>
>>>> I have a strongly typed dataset in my winform app. I need to access a
>>>> specific command of a specific query of a specific table adapter of a
>>>> specific table in the dataset in my code in one of the forms? How can I
>>>> achieve this?
>>>>
>>>> I need something like this;
>>>>
>>>> x = MyDataset.MyTable.MyTableTableAdapter.MyQueryOne.CommandText
>>>>
>>>> Thanks
>>>>
>>>> Regards
>>>>
>>>

>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing query command John Microsoft VB .NET 18 29th Jan 2009 04:39 PM
Accessing Windows NET SEND command =?Utf-8?B?TWljaw==?= Microsoft Frontpage 1 15th Oct 2005 09:14 PM
Re: Accessing command parameters in code Imran Koradia Microsoft Dot NET Framework Forms 0 16th Sep 2004 04:03 PM
Accessing command parameters in code =?Utf-8?B?SGVucnk=?= Microsoft Dot NET Framework Forms 0 16th Sep 2004 03:01 PM
api for accessing at command Jeff Kish Microsoft Windows 2000 Developer 2 11th Feb 2004 07:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:09 PM.