1
Beginner question you are picking to learn.
Next: I have a variable "taxaDI".
I capture this information by the Capturrtaxadi method().
Then, this value must be inserted into a database by Inserirbanco().
What happens is that I am not able to bring the amount captured by the first method for the second insert into the bank.
When I try to insert in the bank it inserts "0".
I think I should use a property, but I don’t have it yet...
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace CapturaFTP
{
class CapturaFTP
{
public static void CapturarTaxaDI()
{
Campos item = new Campos();
string data = DateTime.Now.AddDays(-2).ToString("yyyyMMdd");
string arquivoFtp = data + "_TAXA_DI.TXT";
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(@Constantes.FTP + arquivoFtp);
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
WebProxy proxyConfigs = new WebProxy(Constantes.proxy, Constantes.portaProxy);
proxyConfigs.UseDefaultCredentials = true;
proxyConfigs.Credentials = new NetworkCredential(Constantes.usuario, Constantes.senha, Constantes.dominio);
request.Proxy = proxyConfigs;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
string taxa = reader.ReadToEnd().Trim();
item.taxaDI = Convert.ToDecimal(taxa) / 10000;}
public static void InsereBanco()
{
Campos item = new Campos();
SqlConnection conexaoBanco = new SqlConnection(Constantes.Banco);
conexaoBanco.Open();
SqlCommand comandoBanco = new SqlCommand(Constantes.judsp001InsereValorDolarSelic, conexaoBanco);
comandoBanco.CommandType = CommandType.StoredProcedure;
comandoBanco.Parameters.AddWithValue("@vr_indice", item.taxaDI);
comandoBanco.Parameters.AddWithValue("@co_indice_economico", Constantes.coIndiceTaxaDI);
int rowsAffected = comandoBanco.ExecuteNonQuery();
}
class Campos
{
public decimal taxaDI { get; set;}
}
}
}
```