Showing posts with label username. Show all posts
Showing posts with label username. Show all posts

Wednesday, March 28, 2012

Parse Return value of SYSTEM_USER

DECLARE @.UserName nvarchar(100)
SELECT @.UserName = SYSTEM_USER

value returned is "Domain\NTSignonName"
What I want is only "NTSignonName"

Is there a function to do this or an easy parse for this in SQL2000?

lqI know I can do:

DECLARE @.UserNameWithDomain nvarchar(100)
SELECT @.UserNameWithDomain = SYSTEM_USER

DECLARE @.UserNameNoDomain nvarchar(100)
SELECT @.UserNameNoDomain =
SUBSTRING(@.UserNameWithDomain,CHARINDEX('\',@.UserN ameWithDomain)+1,100)

I'm hoping for something more aesthetic.|||laurenq uantrell (laurenquantrell@.hotmail.com) writes:
> I know I can do:
> DECLARE @.UserNameWithDomain nvarchar(100)
> SELECT @.UserNameWithDomain = SYSTEM_USER
> DECLARE @.UserNameNoDomain nvarchar(100)
> SELECT @.UserNameNoDomain =
> SUBSTRING(@.UserNameWithDomain,CHARINDEX('\',@.UserN ameWithDomain)+1,100)
> I'm hoping for something more aesthetic.

I don't know if it's more esthetic, but parsename() is an alternative.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx

Saturday, February 25, 2012

Parameters and ReportViewer

I have a report in which I am trying to get a parameter to be displayed in a textbox. I have declared a parameter in my .rdlc called UserName and the expression in the textbox is as follows...

=Parameters!UserName.Value

With that said, I have code in the window containing my ReportViewer to set the parameters and run my report as shown below...

string UserName = "test";

List<ReportParameter> paramList = new List<ReportParameter>();

paramList.Add(new ReportParameter(UserName));

this.baseReportViewer.LocalReport.SetParameters(paramList);

this.baseReportViewer.RefreshReport();

With these things in mind, can anyone here provide me with a reason as to why my report on comes up with a message stating "An error occurred during local processing. One or more parameters required to run the report have not been specified." ?

If I remove the parameter and text box and strip out the code pertaining to the paramter in my window, the report runs without error.

Any ideas?

Answered my own question and it was a total noob mistake.

Assuming I have a parameter in my report named "UserName," the code in my form would need to look like the following...(I've highlighted the change in red)

string UserName = "test";

List<ReportParameter> paramList = new List<ReportParameter>();

paramList.Add(new ReportParameter("UserName", UserName));

this.baseReportViewer.LocalReport.SetParameters(paramList);

this.baseReportViewer.RefreshReport();