Add a search on this enum
> struct ClientQueryParams {
>         public string Lastname;
>         public string Firstname;
>         public int NumberOfOrders;
          public ClientQueryFlags Flags;
> }

[Flags]
enum ClientQueryFlags
{
    None = 0,
    Lastname = 1,
    Firstname = 2,
    NumberOfOrders = 3
}

When do as appropriate in the WS for null in your select statement

Usage

Obj.Query(new ClientQueryParams("","adam", 0, ClientQueryFlags.Firstname));

> -----Original Message-----
> From: Zecharya, Bar (FIRM) [mailto:[EMAIL PROTECTED]
> Sent: 30 June 2004 14:18
> To: [EMAIL PROTECTED]
> Subject: [ADVANCED-DOTNET] structs, namespaces, webservices and DBNull
>
> I have a webservice method that returns the results of an SQL
> query, and I want to encapsulate the SQL parameter values in
> a struct, like so:
>
> struct ClientQueryParams {
>         public string Lastname;
>         public string Firstname;
>         public int NumberOfOrders;
> }
>
> In a separate ASP.NET application the user can choose more than one
> parameter: say the query is for "client", the user can input
> search values for lastname, firstname etc.  The SQL is something like:
>
> SELECT * FROM Clients WHERE (@lastname IS NULL OR
> [EMAIL PROTECTED]) AND (@firstname IS NULL OR [EMAIL PROTECTED])
>
> The web app sets the struct's property to null, and the
> webservice sets the SQL parameter values to DBNull.Value if
> the struct's property is null, or the property's value if
> it's not null.
>
> * Problem 1: Passing a null value *
> The problem is when the struct's property is a value type
> such as Int32, that can't be null.  How to distinguish
> between when the user queries for all clients with no orders
> and when the client isn't interested in the number of orders,
> because the default value of an int is 0?
>
> * Problem 2: referencing the same type in two ASP.NET apps *
> I've tried using the type "DBInt", only to run into a
> compiler error where the calling app sets the struct's
> properties before sending it to the web service.
>
> myStruct.NumberOfOrders = 1; "Cannot implicitly convert 'int'
> to 'webServiceNamespace.DBInt'"
> or
> DBInt numOrders = 1; // this works - there is an implicit conversion!
> myStruct.NumberOfOrder = numOrders; // "Cannot implicitly
> convert 'clientNamespace.DBInt' to 'webServiceNamespace.DBInt'
>
> Even if I put class that defines DBInt in a separate .dll,
> referenced in both projects, I get the same error: apparently
> the web reference created by VS.NET adds the webservice's
> namespace even though the same .dll is referenced in the
> calling app too.
>
> Basically, I'm looking for either another way to encapsulate
> and pass SQL parameters (which could be null) to a web
> service, or a way to resolve this compiler error.
>
> Thanks,
> Bar
>
> ===================================
> This list is hosted by DevelopMentor(r)  http://www.develop.com
> Some .NET courses you may be interested in:
>
> NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
> http://www.develop.com/courses/gaspdotnetls
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to