Click here to Skip to main content
15,888,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I select excel file.But I dont read excel column value and I dont set datatable.Excel column same datagrid column value.

How to read excel file and set datagrid.

In addition I take this error.Why?

//this error is DataTable is an ambigues reference betweenMicrosoft.Office.Interop.Excel.DataTable and System.Data.DataTable

What I have tried:

using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace MyWpfProject
    {
        class VMInsertFile
        {
           public ContactBtnClickExcelCommand   {
             get { return contactBtnClickExcelCommand; }
             set{  contactBtnClickExcelCommand= value; OnPropertyChanged();
           }

           public InsertOpenDialog  {
             DataTable dt=new DataTable();   //this error is DataTable is an ambigues reference betweenMicrosoft.Office.Interop.Excel.DataTable and System.Data.DataTable
             string con =
  @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}" + 
  @"Extended Properties='Excel 8.0;HDR=Yes;'";    
using(OleDbConnection connection = new OleDbConnection(con))
{
    connection.Open();
    OleDbCommand command = new OleDbCommand("select * from [Sheet1$]", connection); 
    using(OleDbDataReader dr = command.ExecuteReader())
    {
         while(dr.Read())
         {
             var row1Col0 = dr[0];
             Console.WriteLine(row1Col0);
         }
    }
          }
Posted
Updated 23-May-19 13:15pm

1 solution

Since you never could have gotten off the ground, this must have been "the" question.

System.Data.DataTable dt = new System.Data.DataTable();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900