Hi,
I have this code with parameter saldo1:
public bool napKI(DateTime data)
{
bool result = false;
int posl_kas_izv = 0;
decimal iznosd = 0;
decimal saldo1 = 0;
int broj=0;
SqlConnection connection = null;
try
{
connection = GetConnection();
connection.Open();
SqlCommand command2 = new SqlCommand("izbrojZapisi", connection);
command2.CommandType = CommandType.StoredProcedure;
command2.Parameters.AddWithValue("@data", data);
int brojac = (int)command2.ExecuteScalar();
if (brojac == 0)
{
posl_kas_izv = 0;
SqlCommand command3 = new SqlCommand("prvosaldo", connection);
command3.CommandType = CommandType.StoredProcedure;
saldo1 = Convert.ToDecimal(command3.ExecuteScalar());
}
else
{
SqlCommand command1 = new SqlCommand("najdiposlKIzvod", connection);
command1.CommandType = CommandType.StoredProcedure;
command1.Parameters.AddWithValue("@data", data);
posl_kas_izv = (int)command1.ExecuteScalar();
SqlCommand command5 = new SqlCommand("presmetajSaldo", connection);
command5.CommandType = CommandType.StoredProcedure;
command5.Parameters.AddWithValue("@idki", posl_kas_izv);
command5.Parameters.AddWithValue("@data", data);
SqlParameter p = new SqlParameter();
p.ParameterName = "@saldo";
p.Direction = ParameterDirection.InputOutput;
p.SqlDbType = SqlDbType.Decimal;
command5.Parameters.AddWithValue("@saldo", saldo1);
saldo1 = Convert.ToDecimal(command5.ExecuteScalar());
}
....
....
when brojac=0, it inserts the right value in the datatable, but when brojac is not 0, saldo1 is 0, insetad of taking into account the last inserted value in the datatable for performing the calculation.Does anybody have an idea where do I make a mistake?
Thanks in advance
Loading
NelPosted Jul 31, 2012, 6:07 AM
Vinoth RajPosted Jul 31, 2012, 5:48 AM
NelPosted Jul 31, 2012, 2:27 AM
Here is the sp code:
ALTER procedure [dbo].[presmetajSaldo]
(
@idki int,
@data DateTime,
@saldo numeric(12,3) output
)
as
Declare @priem numeric(12,3)
Declare @isplata numeric(12,3)
declare @saldo1 numeric(12,3)
select @priem = sum(iznosden) from blagajna_jspturs
where data=@data and vp>=0 and vp<=10
select @isplata = sum(iznosden)
from blagajna_jspturs
where vp>10 and data=@data
set @saldo1 = isnull(@saldo,0) + (isnull(@priem,0)) - (isnull(@isplata,0))
update Kasovizvestaj
set
idki=@idki,
saldo=@saldo1
where data=@data
select saldo from Kasovizvestaj
return
And I don't understand what "profiler call" is? Would you please excuse my ignorance and tell me what does it mean?
Thanks a lot for everything
P.S. If I don't put the bolded row, it calculates correctly, but when I put it, it throughs only the last entered value for saldo in the data table .
Vinoth RajPosted Jul 30, 2012, 7:31 AM