Default and NULL parameters in stored procedures

Posts   
 
    
hyankov
User
Posts: 5
Joined: 27-Sep-2005
# Posted on: 27-Sep-2005 15:21:10   

Hello.

I have the following problem: using your tool we can not call stored procedures with their default values (skipping parameter) or NULL values. I searched the forum and found that: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=2929 which is kind of work-around for the NULL problem (no need to comment the type safety issue). Is there any solutin for the default parameters?

I am sorry if I post in the wrong section or if this problem is already discussed, but I didn't find any answer for my question on the site and forum.

Thank you so much.

Drewes
User
Posts: 67
Joined: 18-Aug-2003
# Posted on: 28-Sep-2005 02:25:12   

What I tried and appears to work is to pass Nothing (vb) for the defautl parameter. I tried this in the vs2005 mode.

hyankov
User
Posts: 5
Joined: 27-Sep-2005
# Posted on: 28-Sep-2005 10:11:03   

But you can't pass null (in C#) where it expects int for example. It is not nullable. Any other ideas?

Thank you.

Drewes
User
Posts: 67
Joined: 18-Aug-2003
# Posted on: 29-Sep-2005 02:48:34   

Well, it worked for me, I also created a C# project, used C# for LLBLGEN etc and same results as for VB. This is my sample code:

System.Data.DataTable dt;

dt = NW2005DALC.StoredProcedureCallerClasses.RetrievalProcedures.CustOrderHist(null);

I changed the custorderhist to default to some value. I returns the correct number of rows. Maybe I am missing something, if so let me know.

hyankov
User
Posts: 5
Joined: 27-Sep-2005
# Posted on: 29-Sep-2005 08:05:43   
public static DataTable CustOrderHist(System.String customerId)

In C#, you can pass 'null' where it expects String, but if it expected Int32 - you can not pass null value. For example, if the signature of the method was:

public static DataTable CustOrderHist(System.Int32 customerId)

you wouldn't be able to pass null. This means that the generated templates restrict you from passing null and skipping parameters. I said why you can't pass null, now I will explain why you can't skip parameters. You can not do it, because the generated method expects, let's say, 4 parameters and if you pass 2 it won't compile.

I hope I explained my problem well this time smile

Drewes
User
Posts: 67
Joined: 18-Aug-2003
# Posted on: 30-Sep-2005 02:54:02   

Now I see what problem you run into. I don't know any easy answers using llblgen, my suggestion would be to see if you can have all parameters as string and then do the conversion in your stored procedure.

hyankov
User
Posts: 5
Joined: 27-Sep-2005
# Posted on: 30-Sep-2005 15:31:42   

OK, thank you.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 03-Oct-2005 12:10:55   

Additionally, see this thread for a slight template change which might offer what you want: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=2929

Frans Bouma | Lead developer LLBLGen Pro
hyankov
User
Posts: 5
Joined: 27-Sep-2005
# Posted on: 04-Oct-2005 08:13:45   

Yeah, I saw it already. It will work for NULL most probably, but not for Default, I think. Anyways, thank you again simple_smile