Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

asp.net 2.0 sqldatasource

Options
  • 25-07-2007 2:27pm
    #1
    Closed Accounts Posts: 120 ✭✭


    Hi,

    I have a sqldatasource which is basically a query which has two input paramaters which are text boxes.

    when the two text boxes are filled out I want the user to click a button.
    When the button is clicked I want the sqldatasource to execute and I want to know the result of the query. The result of the query is only going to have 1 answer.

    I want to be able to do something like

    txtresult.text = sqldatasource1.result

    is there a simple command for this, can't seem to find it. I read about sqldatareader but doesn't seem to be an option.


Comments

  • Moderators, Science, Health & Environment Moderators Posts: 8,950 Mod ✭✭✭✭mewso


    The SqlDataSource is designed to be used in conjunction with the datacontrols and is best used for multiple results. for what you want to do you would be much better off just accessing the db in code to get a single result and assigning that value to a label or whatever.


  • Registered Users Posts: 2,931 ✭✭✭Ginger




  • Registered Users Posts: 43 Joe-Bloggs


    Easiest way of doing this is the following.

    HTML Code:
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <input id="Submit1" type="submit" value="submit" /><br />
            <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <asp:Literal ID="Literal1" Text='<%# Eval("Returned_Column") %>' runat="server" />
            </ItemTemplate>
            </asp:Repeater>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
    

    VB Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Page.IsPostBack Then
                SqlDataSource1.SelectParameters.Add("Parameter1", TextBox1.Text)
                SqlDataSource1.SelectParameters.Add("Parameter2", TextBox2.Text)
    
                Repeater1.DataSource = SqlDataSource1
                Repeater1.DataBind()
            End If
        End Sub
    

    The form is submitted and on the postback the values are got. The datasource is then called and the result bound to a repeater or any other data control.

    That's how I'd do it


  • Closed Accounts Posts: 120 ✭✭samelterrance


    Ginger wrote:


    This worked really well, thanks for the help Ginger.


Advertisement