Hi,
Phil Mc wrote:
But when I try to do the same in .NET, the value '0.0 is
always placed in the null value fields.
I'd have expected a SQL execution erorr instead -- makes me wonder what else
may be going on -- but try the following changes to your C# code and stored
procedure (only relevant parts reproduced, comments added):
// removed:
// cmdLoadFundStatistics.Parameters.Add("@turnover_ra tio", SqlDbType.Float,
10);
//
// We can add and assign value in one line
if(tratio != null)
cmdLoadFundStatistics.Parameters.Add("@turnover_ra tio",
SqlDbType.Float).Value = tratio;
// removed:
// else
// cmdLoadFundStatistics.Parameters["@turnover_ratio"].Value =
System.DBNull.Value;
//
// Instead of adding parameter with DBNull.Value for Value, we don't
// add it at all.
if(cap != null)
cmdLoadFundStatistics.Parameters.Add("@market_cap" ,
SqlDbType.Float).Value = cap;
Give the same treatment to any other optional parameters. Now, on to the
stored procedure:
ALTER PROCEDURE dbo.sp_pcom_LoadFundStatistics_TEST
@fundID char(10),
@year_d smallint,
@mnth_d smallint,
@turnover_ratio float = null, /* give parameter default value of null
*/
@market_cap float = null,
@pe_ratio float,
@standard_deviation float
AS
/* whatever */
If that doesn't help, make sure you don't have default value constraints for
these columns.
--
Chris Priede