Showing posts with label fetch. Show all posts
Showing posts with label fetch. Show all posts

Monday, March 19, 2012

can I bind a Label control to a SqlDataSource to display one field from a table?

Hi,

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 thisSmile [:)]|||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?

Friday, February 10, 2012

calling use @dbname in a cursor

Folks,
I am trying to use a cursor to run space check on each db on the server
OPEN cur_DBs
FETCH NEXT FROM cur_DBs INTO @.DBName
WHILE @.@.FETCH_STATUS = 0
BEGI
--**********************************************************************************************************************
use @.DBName
won't let me do the "use @.dbname" to switch to the db I want to use.
Any ideas?
Thanks,
MPMTry:
sp_MSforeachdb 'EXEC [?].dbo.sp_spaceused'
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"MANCPOLYMAN" <MANCPOLYMAN@.discussions.microsoft.com> wrote in message
news:8CC1C001-4D22-43C3-A0FF-C32F13EBB2AC@.microsoft.com...
> Folks,
> I am trying to use a cursor to run space check on each db on the server
> OPEN cur_DBs
> FETCH NEXT FROM cur_DBs INTO @.DBName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> --**********************************************************************************************************************
> use @.DBName
> won't let me do the "use @.dbname" to switch to the db I want to use.
> Any ideas?
> Thanks,
> MPM|||Tibor,
I behold the beauty of the internet. Exactly what I am looking for.
Thanks a lot,
Brian
"Tibor Karaszi" wrote:
> Try:
> sp_MSforeachdb 'EXEC [?].dbo.sp_spaceused'
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "MANCPOLYMAN" <MANCPOLYMAN@.discussions.microsoft.com> wrote in message
> news:8CC1C001-4D22-43C3-A0FF-C32F13EBB2AC@.microsoft.com...
> > Folks,
> >
> > I am trying to use a cursor to run space check on each db on the server
> >
> > OPEN cur_DBs
> > FETCH NEXT FROM cur_DBs INTO @.DBName
> > WHILE @.@.FETCH_STATUS = 0
> > BEGIN
> > --**********************************************************************************************************************
> >
> > use @.DBName
> >
> > won't let me do the "use @.dbname" to switch to the db I want to use.
> >
> > Any ideas?
> >
> > Thanks,
> > MPM
>
>