If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > SQLDataSource SelectCommand

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-09-08, 11:00
christyxo christyxo is offline
Registered User
 
Join Date: Oct 2003
Location: London
Posts: 291
Question SQLDataSource SelectCommand

Hi,

I'm fairly new to ASPX and I've spent the last week trying to figure out how to do this and this is my last resort. My selectcommand statement reads (in part) as;


"SELECT Tbl_2.Word AS Word2, Tbl_1.Word AS Word1..."


My aim is that instead of "Select Tbl_2.Word", I want to use the results within a dropdown list to pick up which table to access therefore something like this (as it works in VBA);


"Select" & Me.DropDownList1.SelectedValue & ".Word AS Word2, " & Me.DropDownList2.SelectedValue & ".Word AS Word1..."


I've tried assigning control parameters, or rewriting the sql at page_load(), however it simply won't work for me. Does anyone have any ideas as to how I could do this?
Reply With Quote
  #2 (permalink)  
Old 03-09-08, 17:47
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Ouch, this sounds like a nasty idea!

What's your justification for this design?
Dynamic SQL is a big can of security holed worms.

Can you post what you've tried so far please?
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 03-21-08, 17:14
christyxo christyxo is offline
Registered User
 
Join Date: Oct 2003
Location: London
Posts: 291
Sorry for the delay.

I actually don't have anything written down on my pages. I keep deleting a re-writing just to get something. My code from my original database was as it is below (although its a lot more complex than what I posted below) I've just made it as simple as possible. All I'm trying to do at the moment is to establish how to do it so I'm using the most simple of statements to generate it. The results are generate within a gridview.

<aspqlDataSource ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:CustomerConnectionString %>"
ProviderName="<%$ ConnectionStrings:CustomConnectionString.ProviderN ame %>"
Selectcommand="SELECT Tbl_Table1.* FROM Tbl_Table1"
EnableViewState="False">

<SelectParameters>

<asp:ControlParameter
ControlID="Table1"
DefaultValue="*"
Name="Param1"
PropertyName="Text"
Type="String" />

</SelectParameters>

</aspqlDataSource>


My VBA in my original database was along the lines of:
"SELECT" & Me.DropDown & ".* FROM "& Me.DropDown

Where the selected value of the dropdown list was the table name.
Reply With Quote
  #4 (permalink)  
Old 03-28-08, 05:51
christyxo christyxo is offline
Registered User
 
Join Date: Oct 2003
Location: London
Posts: 291
Actually I've done it now...

I've set the initial selectcommand to run a statement that doesn't display any results, and I've written the SQL string that I need within a page load event, so on page load the select command is re-written. It seemed to do the job.

There isn't anything wrong in doing it this way is there?
Reply With Quote
  #5 (permalink)  
Old 04-01-08, 15:25
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
I would set the command source to be a commandtable and change the text in page load.

You can cancel select for the sqldatasource by trapping it's onselect event (or whatever it's called) and setting cancel = -1
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On