CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> .NET

 Where Condition Using Session Variables

Print topic Send  topic

Author Message
kescott


Posts: 49
Posted: 09/11/2008, 7:52 AM

I have a custom session variable that is created when a user logs in the application named "theLoggedInVendor" that checks which vendor is logged.

In the employees grid, it displays the following:

---------------------------------------|
TotalActive: (3)___________|
---------------------------------------|
Name__|Vendor__|Status__|
---------------------------------------|
Bob___|Comp1___|Active__|
Mar___|Comp1___|Active__|
Joe___|Comp2___|Active__|
---------------------------------------|

My Code is the following:
EmployeesTotalActive.Text = (new TextField("","Total Active: "+Settings  
.vid_connectionDataAccessObject.ExecuteScalar("SELECT count(*) FROM Employees WHERE   
status = 'Active'"))).GetFormattedValue("");

However, I want it to display the TotalActive (2) for Bob or Mary
----------------------------------------|
theLoggedInVendor:Comp1_|
TotalActive: (2)___________|
---------------------------------------|
Name__|Vendor__|Status__|
--------------------------------------|
Bob___|Comp1___|Active__|
Mar___|Comp1___|Active__|
--------------------------------------|


and if Joe is logged in he will see
---------------------------------------|
theLoggedInVendor:Comp1_|
TotalActive: (1)___________|
---------------------------------------|
Name__|Vendor__|Status__|
---------------------------------------|
Joe___|Comp2___|Active__|
---------------------------------------|

I tried to do it this way, but my code below now is displaying the count of everyone in the table, I need the count to be specific to user based off the theLoggedInVendor Session variable:

Can I call and compare my custom session varible in where clause like this?
EmployeesTotalActive.Text = (new TextField("","Total Active: "+Settings  
.vid_connectionDataAccessObject.ExecuteScalar  
("SELECT count(*) FROM Employees WHERE (vendor ='{theLoggedInVendor}' AND  
status = 'Active'")))).GetFormattedValue("");

_________________
B.S. of Computer Science
Class of 2005
Norfolk State University
Norfolk, VA
http://www.nsu.edu
View profile  Send private message
kescott


Posts: 49
Posted: 09/11/2008, 1:34 PM

I think I'm getting closer now because I think it is reading the column value, but I get another error message now that explains I have an invalid column name.

Error message: Invalid column name 'Wipro'

My code:
//Label TotalActive Event BeforeShow. Action Custom Code   
  
String LoggedInVendor;  
  
if (System.Web.HttpContext.Current.Session["theLoggedInVendor"] !=null)  
  
{  
LoggedInVendor = System.Web.HttpContext.Current.Session["theLoggedInVendor"].ToString();  
  
EmployeesTotalActive.Text = (new TextField("","Total Active: "+Settings  
.vid_connectionDataAccessObject.ExecuteScalar  
("SELECT count(*) FROM Employees WHERE status = 'Active'   
AND vendor =" + LoggedInVendor))).GetFormattedValue("");  
}

_________________
B.S. of Computer Science
Class of 2005
Norfolk State University
Norfolk, VA
http://www.nsu.edu
View profile  Send private message
kescott


Posts: 49
Posted: 09/12/2008, 2:32 AM

Okay, I think I have this figured out, now. :-D

Basically, I assign a value to the variable called LoggedInVendor, like this
LoggedInVendor = System.Web.HttpContext.Current.Session["theLoggedInVendor"].ToString();

Then count all Employees that are 'Active' and relate to the current logged in vendor, called 'theLoggedInVendor'.

When I try it with the static look code below, it counts all Employees that are 'Active' and relate to the vendor ='theLoggedInVendor'
  
EmployeesTotalActive.Text = (new TextField(" ","Total Active: "+Settings  
.vid_connectionDataAccessObject.ExecuteScalar  
("SELECT count(*) FROM Employees WHERE   
status = 'Active' AND vendor = ' " + LoggedInVendor + " ' ")))  
.GetFormattedValue(" ");))).GetFormattedValue(" ");  
:-)
_________________
B.S. of Computer Science
Class of 2005
Norfolk State University
Norfolk, VA
http://www.nsu.edu
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.