1. Welcome Guest! In order to create a new topic or reply to an existing one, you must register first. It is easy and free. Click here to sign up now!.
    Dismiss Notice

Passing null parameters to strongly typed datacontext

Discussion in 'Microsoft News' started by NewsBot, Apr 24, 2008.

  1. NewsBot

    NewsBot I Got News

    Joined:
    Feb 8, 2006
    Messages:
    1,813
    Operating System:
    Windows Vista Home Premium
    OK, next step.* I've now got a strongly typed DataContext which I've associated with a stored procedure in my SQL Server 2005 database.* This SP does allow for nulls to be passed in for various parameters; in fact passing in nulls for some of the parameters will result in more data being returned, which is exactly what I want.* However, I don't know how to pass in nulls for the parameters of the method that is my SP associated with the LINQ to SQL result class.* I'll do something like the following to declare variables to pass to the method of the result class:

    <b>string firstName, lastName, socialSecurityNo;
    DateTime? dateOfBirth;

    firstName = "Fred";
    lastName = "Flintstone";

    MyStronglyTypedDataContext dc = new MyStronglyTypedDataContext();</b>

    System.Data.LINQ.ISingleResult result = dc.spCheckData(firstName, lastName, socialSecurityNo, dateOfBirth);

    As you can see, I've left the <b>socialSecurityNo</b> and <b>dateOfBirth</b> values alone, which will mean that <b>socialSecurityNo</b> will likely equal string.Empty and <b>dateOfBirth</b> will be null.* These are allowed for in the SP, but running this results in nothing being returned.* I know this is not true, because if I run the same query in SSMS I get results.* So, how do I assign values to those variables so that when the call to spCheckData() occurs it will pass in null values to the SP?



     

Share This Page