我已经用 SQL 编写了这个函数
alter function TVprest (@emitente int, @mes int, @ano int)
returns float
as
begin
declare @tcu float;
select @tcu = sum(cast(vtprest as money))
from ctrc
where emitente = @emitente and MONTH (EMISSAODATA ) = @mes
and YEAR (EMISSAODATA)=@ano and status = 'A'
if (@tcu is null)
set @tcu = 0;
return @tcu
end
并尝试使用以下代码在 C# 中调用相同的函数:
public double TVprest (int emitente, int mess, int anno)
{
double saida;
SqlConnection abre1 = Tconex.GetConnection();
SqlDataAdapter da3 = new SqlDataAdapter();
if (abre1.State == ConnectionState.Closed) { abre1.Open(); }
SqlParameter emit = new SqlParameter("@emitente", SqlDbType.Int);
emit.Value = emitente;
SqlParameter mes = new SqlParameter("@mes", SqlDbType.Int);
mes.Value = mess;
SqlParameter ano = new SqlParameter("@ano", SqlDbType.Int);
ano.Value = ano;
SqlCommand TotalF = new SqlCommand("SELECT dbo.Tcupom(@emitente,@mes,@ano),", abre1);
TotalF.CommandType = CommandType.Text;
saida = Convert.ToDouble(TotalF.ExecuteScalar());
return saida;
}
运行时出现此错误:
无法将参数值从 SqlParameter 转换为 Int32
怎么了?使用这些参数调用函数:
double Tvprest = impx.TVprest(504, 5, 2013);
lblVtprest.Text = Tvprest.ToString();