public Form1() { InitializeComponent(); string pathofexecutable = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); OleDbConnection oledbConn = null; oledbConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pathofexecutable + "\\Book3105.xlsx;Mode=ReadWrite;Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';"); oledbConn.Open(); DataSet ds = new DataSet(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = oledbConn; cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM [sheet1$]"; OleDbDataAdapter oleda = new OleDbDataAdapter(); oleda = new OleDbDataAdapter(cmd); oleda.Fill(ds); ds.Tables[0].TableName = "DataTable1"; this.DataTable1BindingSource.DataSource = ds; this.reportViewer2.RefreshReport(); }
Thanks, A2H My Blog
Login to post response