public int deductfromaccount(string account, string amount, System.Data.SqlClient.SqlCommand comm)
    {
        //actually remove the amount from the account, check the balance, return the balance
        string sql = "update huber_bankaccounts set balance = balance - @amount where accountnumber = @accountnumber";
        comm.CommandText = sql;
        comm.Parameters.Clear();
        comm.Parameters.AddWithValue("@amount", amount);
        comm.Parameters.AddWithValue("@accountnumber", account);

        comm.ExecuteNonQuery();

        sql = "select balance from huber_bankaccounts where accountnumber = @accountnumber ";

        comm.CommandText = sql;
        comm.Parameters.Clear();
        comm.Parameters.AddWithValue("@accountnumber", account);

        var result = comm.ExecuteScalar();

        if (result != null)
        {
            return int.Parse(result.ToString());
        }
        else
        {
            return -1; // (really an error code)
        }
    }
		private long GetLastFilesetID(System.Data.IDbCommand cmd)
		{
			long id = -1;
			var r = cmd.ExecuteScalar(@"SELECT ""ID"" FROM ""Fileset"" ORDER BY ""Timestamp"" DESC LIMIT 1");
			if (r != null && r != DBNull.Value)
				id = Convert.ToInt64(r);
				
			return id;
		}
        public override int ExecuteScalar(System.Data.Common.DbCommand command)
        {
            command.CommandText = command.CommandText + "; SELECT CONVERT(INT, SCOPE_IDENTITY())";

            int lastid = 0;

            try
            {
                command.Prepare();
                lastid = (int)command.ExecuteScalar();
            }
            catch (Exception e)
            {
                throw e;
            }

            return lastid;
        }
 public void ExecCommand(System.Data.SqlClient.SqlCommand i_cmd)
 {
     i_cmd.CommandType = CommandType.StoredProcedure;
     if (m_HaveTrans)
     {
         i_cmd.Connection = m_Connection;
         i_cmd.Transaction = m_Trans;
     }
     else
     {
         i_cmd.Connection = CProvider.getConnection();
         i_cmd.Connection.Open();
     }
     i_cmd.CommandTimeout = C_COMMAND_TIME_OUT;
     i_cmd.ExecuteScalar();
     if (!m_HaveTrans)
     {
         i_cmd.Connection.Close();
     }
 }
Exemple #5
0
        protected override void Cadastrar(System.Data.IDbCommand cmd)
        {
            if (localidade == null)
                throw new ArgumentNullException("Localidade não pode ser nula em um endereço.");

            if (!localidade.Cadastrado)
                CadastrarEntidade(cmd, localidade);

            cmd.CommandText = "SELECT MAX(id) FROM endereco WHERE pessoa = " + DbTransformar(pessoa.Código);
            object mId = cmd.ExecuteScalar();

            if (mId != null && mId != DBNull.Value)
                id = Convert.ToUInt32(mId) + 1;

            base.Cadastrar(cmd);
        }
Exemple #6
0
        public long ObterNovoCodigo(System.Data.IDbCommand v_oCommand, String v_sNomeSequence)
        {
            try
            {
                long m_iCodigo = 0;
                string m_sSQL = string.Empty;

                m_sSQL = obterQueryNexVal(v_sNomeSequence);
                v_oCommand = ObterCommand(m_sSQL);
                m_iCodigo = Util.UtDbNet.CampoLongo(v_oCommand.ExecuteScalar());

                v_oCommand.Dispose();
                return m_iCodigo;
            }
            catch (Exception ex)
            {
                throw new Dor.Util.OperacaoInvalidaBD(ex);
            }
        }
Exemple #7
0
        public static object ExecuteScalar(System.Data.SqlServerCe.SqlCeCommand command)
        {
            bool retry = false;

            try
            {
                return command.ExecuteScalar();
            }
            catch (System.Data.SqlServerCe.SqlCeException ex)
            {
                if (ex.NativeError == 0)
                {
                    retry = true;
                }
                else
                {
                    throw;
                }
            }

            if (retry)
            {
                command.Connection.Close();
                command.Connection.Open();

                return command.ExecuteScalar();
            }
            else
                return null;
        }
Exemple #8
0
        protected override void Cadastrar(System.Data.IDbCommand cmd)
        {
            cmd.CommandText = "SELECT MAX(id) FROM telefone WHERE pessoa = " + DbTransformar(pessoa.Código);
            object mId = cmd.ExecuteScalar();

            if (mId != null && mId != DBNull.Value)
                id = Convert.ToUInt32(mId) + 1;

            base.Cadastrar(cmd);
        }
Exemple #9
0
        public static object executeScalar(System.Data.Common.DbCommand cmd)
        {
            cmd.Connection = new SqlConnection(conStr);
            try
            {
                cmd.Connection.Open();
                return cmd.ExecuteScalar();
            }
            catch (Exception ex) {
                throw ex;
                return null;
            }

        }