1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help with ASP.NET SelectCommand

Discussion in 'C#' started by circuscircus, Jun 14, 2007.

Thread Status:
Not open for further replies.
  1. #1
    I need the SelectCommand to take it from within the <script> because I need to make it so the firstname and lastname is retrieved from the Request.QueryString

    <%@ Control Language="c#" AutoEventWireup="false" Codebehind="default.ascx.cs" Inherits="Octane8.Applications.Announcements.Website.Default" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>

    <script language="C#" runat="server">
    protected void Page_Load(object sender, EventArgs e){
    SqlDataSource1.SelectCommand = "SELECT [ContactStatusID], [ContactStatusID_HideLevel], [OrgName], [Title], [Suffix], [RegionFellow], [PrintFellow], [PrintState], [OnlinePwd], [ReligiousOrgs], [CharitableOrgs], [EducationOrgs], [AgriculturalOrgs], [HealthOrgs], [Created], [Updated], [LastEdit], [LastName], [SalutationID], [SalutationID_HideLevel], [MiddleInit], [FirstName], [PreferredMailingAddressID], [BusinessOrgs], [WebSite], [WebSite_HideLevel], [SectorID], [SectorOther], [SectorID_HideLevel], [SectorRole], [GeographicAreaID], [GeographicAreaID_HideLevel], [CensusDispositionID], [CensusDisplositionID_HideLevel], [InterestAreaOther], [OnlineNoPwd], [Comments], [Comments_HideLevel], [Bio_HideLevel], [Bio], [Picture], [PermissionComments], [Picture_HideLevel], [SocialServiceOrgs], [CommunityDevelopmentOrgs], [AdvocacyOrgs], [ID] FROM [tContact] WHERE Firstname = 'Jim' AND Lastname = 'Kim'";
    DetailsView1.DataSource = SqlDataSource1;
    DetailsView1.DataBind();

    }
    </script>

    <div>
    <asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="SqlDataSource1" Height="50px"
    Width="125px" AutoGenerateEditButton="True" DefaultMode="Edit" EnablePagingCallbacks="True" EnableTheming="True">
    </asp:DetailsView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=mssql10.digitalhousing.net;Persist Security Info=True;User ID=KFLA2007;Password=DeeN29SioY30EoiU"
    SelectCommand="SELECT [ContactStatusID], [ContactStatusID_HideLevel], [OrgName], [Title], [Suffix], [RegionFellow], [PrintFellow], [PrintState], [OnlinePwd], [ReligiousOrgs], [CharitableOrgs], [EducationOrgs], [AgriculturalOrgs], [HealthOrgs], [Created], [Updated], [LastEdit], [LastName], [SalutationID], [SalutationID_HideLevel], [MiddleInit], [FirstName], [PreferredMailingAddressID], [BusinessOrgs], [WebSite], [WebSite_HideLevel], [SectorID], [SectorOther], [SectorID_HideLevel], [SectorRole], [GeographicAreaID], [GeographicAreaID_HideLevel], [CensusDispositionID], [CensusDisplositionID_HideLevel], [InterestAreaOther], [OnlineNoPwd], [Comments], [Comments_HideLevel], [Bio_HideLevel], [Bio], [Picture], [PermissionComments], [Picture_HideLevel], [SocialServiceOrgs], [CommunityDevelopmentOrgs], [AdvocacyOrgs], [ID] FROM [tContact]"
    UpdateCommand="">
    </asp:SqlDataSource>

    </div>
     
    circuscircus, Jun 14, 2007 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    Instead of doing inline SQL - you can use yoru strongly typed datasets and just pass it in your querystring values and databind to thhe DataTable's that the Datasets push out :)
     
    ccoonen, Jun 14, 2007 IP
  3. newbish

    newbish Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Even better if your using .NET 2.0 take a look at objectdatasources they can make reuse very nice later.
     
    newbish, Jun 19, 2007 IP
  4. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #4
    objectdatasources can use the Strongly Typed Datasets as the datasource ;) Best of both worlds!
     
    ccoonen, Jun 20, 2007 IP
  5. yugolancer

    yugolancer Well-Known Member

    Messages:
    320
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #5
    But he is already using the datasource object. Reread the original post.

    ASP.NET has built-in functionality for this :

    consider the folowing code sample and adapt for your needs

    
    <!-- assuming that your URL string looks like www.domain.com/page.aspx?fName=kulrom&lName=mylastname -->
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
                ProviderName="<%$ ConnectionStrings:testConnectionString.ProviderName %>" 
                SelectCommand="SELECT [id], [FirstName], [LastName], [field3] FROM [Table1] WHERE FirstName=@fName AND LastName=@lName">
                <SelectParameters>
                <asp:QueryStringParameter Name="fName" Type="String" QueryStringField="fName" />
                <asp:QueryStringParameter Name="lName" Type="String" QueryStringField="lName" />
                </SelectParameters>
            </asp:SqlDataSource>
    
    Code (vb):
    HTH
    Regards :)
     
    yugolancer, Jul 2, 2007 IP
Thread Status:
Not open for further replies.