What's the 'new' declarative way to fetch one field from a SQL table and display the result in a Label control?
I have a users table with a fullname field. I want to query the table and retrieve the fullname where the usertable.username = Session("loggedinuser")
I can make the SqlDataSource ok that has the correct Select query, but not sure how to bind the label to that.
thanks,
BruceThe only way I know of, and I hope there is a better way, but I don't know it is to put a formview control on the page. Bind the formview to the datasource, and place the label within the formview, then databind the label to the fullname column.|||Thanks Motley,
I did end up doing that approach. It works ok, just feels a little cumbersome..but maybe it's the correct way for now.
I just feel like there's a missing control that lets you easily bind to a singe output parameter from a query/stored procedure.
-Bruce|||I agree bruce, but unfortunely I lost my inventation to the meeting where the MS team discussed this
|||If you're wanting to retrieve the value from a return (output) parameter - that is possible. Take a look at the SqlDataSource controls Selected event. In that event, after the select has taken place, you can retrieve the output paramter's value...
Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Selected
Me.txtWhatEver.Text = e.Command.Parameters("parameterNameHere").Value
End Sub
This might help too... http://www.asp.net/QuickStart/util/srcview.aspx?path=~/aspnet/samples/data/RetValAndOutputParams.src
I do wish there were a way to retrieve data other than what can be returned in an output parameter... like a field in a DataRow for example. The data controls (like a FormView) are doing this somehow... so why can't I get access to that some functionality in code-behind?
No comments:
Post a Comment