0

I want to show in C # Message Fill that it is exported from Excel. I select the excel file from the Internet via FileDialog. and I want to show the data in the message box in the first column in Excel.

    private void button2_Click(object sender, EventArgs e)
    {
        OpenFileDialog OFD = new OpenFileDialog()
        {
            Filter = "Excel Dosyası |*.xlsx| Excel Dosyası|*.xls",
            Title = "Excel Dosyası Seçiniz..",
            RestoreDirectory = true,
        };
        if (OFD.ShowDialog() == DialogResult.OK)

        {
            string DosyaYolu = OFD.FileName;
            string DosyaAdi = OFD.SafeFileName; 

            OleDbConnection baglanti = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + DosyaYolu + "; Extended Properties='Excel 12.0 xml;HDR=YES;'");
            baglanti.Open();
            OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [Sayfa1$]", baglanti);
            DataTable DTexcel = new DataTable();
            da.Fill(DTexcel);
            MessageBox.Show(da.ToString());
            baglanti.Close();
        }
    }

Screenshots of the application and of the desired output:

enter image description here

enter image description here

RajeshKumar R
  • 15,445
  • 2
  • 38
  • 70
Yunus
  • 55
  • 5
  • There is no implementation of `DataAdapter.ToString()` that would dump the content. Also, you're probably interested in the contents of the `DTexcel` object? – Cee McSharpface Jan 05 '18 at 13:55

1 Answers1

0

You have to acces the DataTable not the DataAdapter, try :

MessageBox.Show(DTExcel.Rows[Rowindex][Columnindex].Value.ToString());
nuuse
  • 109
  • 1
  • 11