views:

210

answers:

1

If I run a stored procedure in my database (SQL 2000) and return the SCOPE_IDENTITY, I receive a value. However, using LINQ to SQL, I get a null value for the Column1 property. Anyone have a suggestion?

A: 

Make sure you have only one SELECT statement at the end of your SP. So, something like this:

IF something
DO something
   SET variables
ELSE
   SET variables

SELECT variables

Also, rename your column in the select statement and possibly cast it into proper data type. Something like this:

SELECT CAST(@variable AS DataType) AS [ColumnName];

I ran into this a week ago because I had 2 SELECT statements in a SP and they were screwing each other up. The SP always did what it was supposed to but it always sent null back. Since I switched to what I wrote above it's worked like a charm.

Hope this helps you

Alex
There are other select statements, but further up the chain. they aren't at the end. there's only one at the end. If I run it in SQL Management Studio, only one result is returned and not multiple results. I will try the column thing. Thanks!
Jason N. Gaylord
It did work. Specifying the exact cast to the type is what seemed to do it. Thanks!!! I'll have to blog about this.
Jason N. Gaylord