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.

ASP.NET C# Query String Requests

Discussion in 'C#' started by WayTooAwesome, Jun 16, 2006.

  1. #1

    I'm pretty new to ASP.NET C#, but I'm currently trying to get a bit better. Right now I'm attempting to make a page that will basically pull information from a database and format it into a handy dandy little table, depending on which ID (Primary Key) I choose to shoot through a Query String.

    So far, I've gotten my code to allow me to manually change the SQL WHERE clause to present different rows of data, but as I said, I'd rather be able to do it through a Query String. As thus, I've thrown in QueryStringParameter in an attempt to get things goin', but that hasn't worked for me.

    Oh, and I *think* that I'm using MS SQL for a database, assuming that's what Microsoft would do with databases made in Visual Studio 2005.
    Here's my code:

            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>"
                SelectCommand="SELECT * FROM [Employee] WHERE ID=@ID">
                 <asp:QueryStringParameter Name="@ID" QueryStringField="t" Type="Int32" />
            <table cellpadding="5" cellspacing="5" border="0">
              <asp:FormView ID="FormView1" runat="server" DataKeyNames="ID" DataSourceID="SqlDataSource1">
                    <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>'></asp:Label><br />
                    <td style="text-align:left; vertical-align:middle"><asp:Label ID="FNameLabel" runat="server" Text='<%# Bind("FName") %>'></asp:Label>
                    <asp:Label ID="LNameLabel" runat="server" Text='<%# Bind("LName") %>'></asp:Label><br />
                    <i><asp:Label ID="TitleLabel" runat="server" Text='<%# Bind("Title") %>'></asp:Label></i><br />
                    <asp:Label ID="PhoneLabel" runat="server" Text='<%# Bind("Phone") %>'></asp:Label><br />
                    <asp:Label ID="URLLabel" runat="server" Text='<%# Bind("URL") %>'></asp:Label>
                    <td style="text-align:left; vertical-align:top; width:200px"><img alt="Picture" height="125" width="125" src="Pictures/<%# Eval("Picture") %>"/></td>
                    <td style="text-align:left; vertical-align:top">Responsibilities:</td>
                    <td style="text-align:left; vertical-align:top"><asp:Label ID="ResponsibilitiesLabel" runat="server" Text='<%# Bind("Responsibilities") %>'>
                    <td style="text-align:left; vertical-align:top">Monthly Goals:</td>
                    <td style="text-align:left; vertical-align:top"><asp:Label ID="MonthlyGoalsLabel" runat="server" Text='<%# Bind("MonthlyGoals") %>'>
                    <td style="text-align:left; vertical-align:top">Miscellaneous Info:</td>
                    <td style="text-align:left; vertical-align:top"><asp:Label ID="MiscLabel" runat="server" Text='<%# Bind("Misc") %>'></asp:Label></td>
    Code (markup):
    So, in short, my question is this: How can get my QueryString to work? I know there's a way, I just don't know how and can't find a way to actually put data into the QueryString to be loaded.

    Oh yeah, I've tried adding ?t=1, ?ID=1, and ?@ID=1 to the end of my URL. The ?t=1 gives me some huge error that says I "Must declare the scalar variable '@ID'." Both ?ID=1 and ?@ID=1 produce basically a page without any of the code between my ASP:FormView tags.

    WayTooAwesome, Jun 16, 2006 IP
  2. iconico

    iconico Peon

    Likes Received:
    Best Answers:
    Trophy Points:
    Ok you're much better learning how to write code-behind pages so you can write proper C# and not just use the objects with no plumbing. Take a look at some of the quickstart tutorials on asp.net and go from there. You'll have a much easier time coding that way, using intellisense and being able to debug will make our life a million times easier.
    iconico, Jun 10, 2008 IP
  3. yugolancer

    yugolancer Well-Known Member

    Likes Received:
    Best Answers:
    Trophy Points:
    Maybe you can try with changing the parameter direction property. SqlCommmand parameters are by default input parameters. Try changing it to Output. Direction="Output"
    Not so sure before i see the whole error message (exception) but that would be my quick tip.
    yugolancer, Jun 11, 2008 IP