locked
customize accessdatasource RRS feed

  • Question

  • User629360359 posted
    <asp:AccessDataSource ID="adsBlank" runat="server" 
        DataFile="~/App_Data/database.mdb" 
        SelectCommand= '<%# "SELECT * FROM " + dropdownlist.Text"%>'
                        ConflictDetection="CompareAllValues" 
                        OldValuesParameterFormatString="original_{0}">
    </asp:AccessDataSource>
    
    
    i wan to set the select statement according to the value in the dropddownlist, but i duno how to code it,
    u can get my idea from sample above.
    please corret that SelectCommand for me, thanks in advance
    Thursday, June 9, 2011 5:09 AM

Answers

  • User-1199946673 posted

    You cannot parameterize the tablename. You better do this in code. In the selectedIndexChanged event of the dropdownlist, something like:

    AccessDataSource1.SelectCommand = "SELECT * FROM " + DropDownList1.SelectedValue
    
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 9, 2011 7:37 AM

All replies

  • User-1696077569 posted

    Use SelectParameter as ControlParameter instead

    <SelectParameters>
    
    <asp:ControlParameter Name=szSO ControlID="dropdownlist" PropertyName="Text"  /> 
    </SelectParameters>
    
    Follow below article...
    http://www.maconstateit.net/tutorials/aspnet20/ASPNET13/aspnet13-05.aspx
    Thursday, June 9, 2011 5:22 AM
  • User629360359 posted

    Use SelectParameter as ControlParameter instead

    <SelectParameters>
    
    <asp:ControlParameter Name=szSO ControlID="dropdownlist" PropertyName="Text"  /> 
    </SelectParameters>
    
    

    can u provide me more detail?  i modified to :

    <asp:AccessDataSource ID="adsBlank" runat="server" 
        DataFile="~/App_Data/database.mdb" 
        SelectCommand= '<%# "SELECT * FROM " + szSO%>'
                        ConflictDetection="CompareAllValues" 
                        OldValuesParameterFormatString="original_{0}">
    
    <SelectParameters>
    <asp:ControlParameter Name=szSO  ControlID="dropdownlist" PropertyName="Text"  /> 
    </SelectParameters>
    
    </asp:AccessDataSource>

    Thursday, June 9, 2011 5:28 AM
  • User-1696077569 posted
    <asp:AccessDataSource ID="adsBlank" runat="server"  
        DataFile="~/App_Data/database.mdb"  
        SelectCommand= "Select * from @tableName"                    ConflictDetection="CompareAllValues"  
                        OldValuesParameterFormatString="original_{0}"> 
     
    <SelectParameters> 
    <asp:ControlParameter Name=tableName  ControlID="dropdownlist" PropertyName="Text"  />  
    </SelectParameters> 
     
    </asp:AccessDataSource>
    Thursday, June 9, 2011 5:39 AM
  • User629360359 posted

    thx for the reply, but still doesn't work anyway. 

    Smile

    Thursday, June 9, 2011 5:46 AM
  • User-1696077569 posted

    Initially dropdown might be empty..Try setting a default value to control parameter

    <SelectParameters>

    <asp:ControlParameter ControlID="dropdownlist1" PropertyName="Text" Name="tableName"  DefaultValue="YourTableName"/>

    </SelectParameters>

    Thursday, June 9, 2011 5:50 AM
  • User-1199946673 posted

    You cannot parameterize the tablename. You better do this in code. In the selectedIndexChanged event of the dropdownlist, something like:

    AccessDataSource1.SelectCommand = "SELECT * FROM " + DropDownList1.SelectedValue
    
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 9, 2011 7:37 AM