?
Solved

c#  Enum use ? Null to determine

Posted on 2007-11-24
10
Medium Priority
?
2,304 Views
Last Modified: 2013-12-16
I want to use a Variable set to NULL when AllCustomers is selected ........I want to use ? technique in this. I dont want to use <System.Nullable>
public enum  EnumCustomers
  {   AllCustomers,
     CaliforniaCustomers,
     NewYorkCustomers
 }

public dataset GetCustomers(EnumCustomers Cust)
  {
       if Cust.AllCustomers = AllCustomers (I want this to be DEFAULT AS NULL and I want to assign it to a variable using C#  ?   statements )
  }
0
Comment
Question by:dotnet0824
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20342827
I guess you want something like this:
public dataset GetCustomers(EnumCustomers Cust)
  {
     if (Cust.AllCustomers == EnumCustomers.AllCustomers)
     {
     }
  } 

public dataset GetCustomers()
{
   return GetCustomers(EnumCustomers.AllCustomers);
}

Open in new window

0
 

Author Comment

by:dotnet0824
ID: 20342903
its like this All I want is to Get Null Value to be assigned to @city
         if AllCustomers is passed I call
                Select * from Customer
               Case Cust.californiaCustomers
                     Select * from Customers where place="CA"
                Case Cust.NewyorkCustomers
                    Select * from Customers where place ="NY"
Now I want to do like this  (I dont want 3 conditions) like above
             if AllCustomers Passed  I want to pass  NULL  which stored proc understands and gets
                     Select * from customer
                             ELSE
                             

=============Stored Proc
Create procude Getcustomer
@city BIT
IF @City is NOT NULL
             Select * from Customers
               Else
                     Select * from customers where City=@City
0
 

Author Comment

by:dotnet0824
ID: 20342914
So in my function  i want to Create a Variable lets say    
if  passed in Value is  AllCustomers   x = Null else x = passsed in value
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20342939
I assume that BIT is not the data type of the City column?

the sql procedure would look like this:
Create procude Getcustomer
  @city VARCHAR(20)
AS
Select * from Customers
where ( City=@City OR @City IS NULL)

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20342945
now, do you have already some code to call the procedure?
0
 

Author Comment

by:dotnet0824
ID: 20342965
ok lets consider the same stored procdure.. now how do i tune my function  to accept NULL when ALLCUSTOMERS Is passed.
I dont want to have  
   3 case Statement ie (Switch)
          I want something like
                                   Case  Null (ie AllCustomers)
                                 
                                      Case else
                                                pass the  EnumPassedvalue

i want to use ? and assign it to variable when Enum is passed and then
               
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 20342973
tell me if this is what you want:

public dataset GetCustomers(string city)
  {
     SqlCommand cmd = new SqlCommand("Getcustomer", youconnectionobject");
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.Add("@city", city)
     
     etc etc etc to fill the dataset from the SqlCommand
     

  }

public dataset GetCustomers()
{
   return GetCustomers(string.empty);
}



and the procedure looking like this:

Create procude Getcustomer
  @city VARCHAR(20) = ''
AS
Select * from Customers
where ( City=@City OR @City IS NULL OR @City = '')


0
 

Author Comment

by:dotnet0824
ID: 20343005
i should have been more clear... sorry about this .  I have just tested
In my function I capture the enum passed into the variable  
 int x = (int)Cust;  (cust being the Enum passed in function)
X gets value 0 if (cust.AllCustomers)  1 if(cust.CalifronaiCustomers) 2 (cust.NewyorkCustomers)
Now If x value ==0  I want to use ? and convert to NULL
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20343060
I am not 100% clear why you actually use an enum...
how does the user "choose"?
if it is a listbox/combo/radio button etc, set the selecteditem.value to the string value you want to search for, and the "all" item to '%'

and your procedure will be like this: (assuming that City is the city name):


Create procude Getcustomer
  @city VARCHAR(20) = '%'
AS
Select * from Customers
where ( City LIKE @City )

0
 

Author Comment

by:dotnet0824
ID: 20343190
Hi Angel 111.. Thanks  alot. I got the answer in ur stored proc. thanks agian
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question