Recording of rows in txt file in c # windowsform

-1

I'm doing a program that queries some Mysql tables and generates a list to which populo in a gridview. After that, I did a C # routine that reads each line and writes to the txt file in c: \ text.txt. So far so good, the problem is that when recording, the program writes line by line in the txt file. What would you like to know is if there is a possibility to make a recording at one time? I would like to put a timer in this accumulator but I can not ...

    
asked by anonymous 26.02.2016 / 20:42

2 answers

0

This function writes to a TXT file, The question of writing in just one look or skip line by line comes from the writeline or write function, thus: Writeline = write by jumping a line. write = write in the same beautiful.

Do this:

StreamWriter wr = new StreamWriter(@"c:\diretorio\seuarquivo.txt", true);
wr.Write("linha");
wr.Write("mesma linha");
wr.Close();

I hope it helps.

    
26.02.2016 / 21:25
0
 public partial class Form1 : Form
    {
        public string a;
        public Boolean importacao;
        StreamReader arquivo;
        public string linha = "";

        public string convertData()
        {
            string data;
            data = Convert.ToDateTime(dtTimerPicker.Value).ToString("yyyyMMdd");
            return data;
        }

        public Form1()
        {
            InitializeComponent();
            selecionaArquivo();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string a = convertData();

            date.Text = a;
        }
        private void selecionaArquivo()
        {
            try
            {
                if (abrirArquivo.ShowDialog() == DialogResult.OK)
                {
                    arquivo = new StreamReader(abrirArquivo.FileName);
                    carregaDataGrid();

                    importacao = true;
                }
                else
                {
                    MessageBox.Show("Não foi selecionado nenhum arquivo");
                    this.Close();

                    importacao = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Não é possível exibir a arquivo.\n\nErro reportado : " + ex.Message);
            }
        }

I did something like this ...

    
11.07.2018 / 18:07