Nel

Nel

  • NA
  • 716
  • 1.1m

The parametar doesn't change

Jul 30 2012 3:56 AM
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

Answers (4)