Import xml data field

Asked

Viewed 54 times

0

I’m making an import of tags from xml to fields of textbox in Windows Form, only that I am not able to import the data fields in the correct format, to a masktextbox in date format.How do I proceed to show on textbox the date in the correct format dd/MM/aaaa.

Follows my code

DataSet ds = new DataSet();

ds.ReadXml(@"C:\Xml_Entrada\" + txt_chave.Text + ".xml");

txt_fornecedor.Text = ds.Tables["emit"].Rows[0]["xNome"].ToString();
txt_cnpj.Text = ds.Tables["emit"].Rows[0]["CNPJ"].ToString();
txt_nota.Text = ds.Tables["ide"].Rows[0]["nNF"].ToString();
txt_ie.Text = ds.Tables["emit"].Rows[0]["IE"].ToString();
txt_emissao.Text = ds.Tables["ide"].Rows[0]["dhEmi"].ToString();
txt_saida.Text = ds.Tables["ide"].Rows[0]["dhSaiEnt"].ToString();

Xml data

<dhEmi>2018-06-15T09:56:51-03:00</dhEmi>

<dhSaiEnt>2018-06-15T09:56:51-03:00</dhSaiEnt>
  • 1

    What format is the date coming from xml?

  • Have you tried with .ToString("dd/MM/yyyy")?

  • I edited the question to put the date that came from xml

  • I’ve tried Richard this way.

1 answer

1


Try to do it this way:

// criar date time 2018-07-24 00:00:00.000
DateTime dt = new DateTime(2018, 7, 24, 00, 00, 00, 000);
String.Format("{0:dd/MM/yyyy}", dt);

You can see more about formatting Datetime in String here.

  • Thiago explains something to me, I’m doing the way you did, but as I’m still new in c#, I’m not able to pass the dt value to my date texbox, my textbox is empty in windowsform

  • As I said, is the data for xml going correctly? And another problem of yours is that the date value is not being displayed in the textbox?

  • That’s right the value does not display in my textbox. txt_output.text = dt

  • Thank you very much Thiago managed to pass the value here to the textbox. Thanks for the help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.