Tengo este código que gurda el excel en la aplicación pero al momento de querer consultar los datos no me muestra los datos en el gridview
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;
using System.IO;
using System.Drawing;
public partial class Agregarexel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void btnUpload_Click(object sender, EventArgs e)
{
try
{
string savePath = @"C:\Users\SISTEMAS 231118\Documents\minicrm\ArchivosExcel\";
if (FileUpload1.HasFile)
{
string fileName = Server.HtmlEncode(FileUpload1.FileName);
string extension = System.IO.Path.GetExtension(fileName);
if (FileUpload1.PostedFile.ContentType == "application/vnd.ms-excel" ||
FileUpload1.PostedFile.ContentType == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
{
savePath += fileName;
FileUpload1.SaveAs(savePath);
//mensajeError(savePath);
//string conexionOLEBD = "provider = Microsoft.Jet.OLEDB.4.0; Data Source = '" + savePath + "'; Extended Properties = Excel 8.0; ";
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.DataSet DtSet;
System.Data.OleDb.OleDbDataAdapter MyCommand;
MyConnection = new System.Data.OleDb.OleDbConnection("provider = Microsoft.Jet.OLEDB.4.0; Data Source = '" + savePath + "'; Extended Properties = Excel 8.0;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Hoja1$]", MyConnection);
MyCommand.TableMappings.Add("Table", "TestTable");
DtSet = new System.Data.DataSet();
MyCommand.Fill(DtSet);
GridView1.DataSource = DtSet;
MyConnection.Close();
}
}
else
{
mensajeError("Solo se permite archivos excel ");
}
}
catch (Exception ex)
{
mensajeError("Error" + ex);
}
}
catch (Exception ex)
¿tiene algún error?, si es así, editar la pregunta para agregar la descripción completa del error.GridView1.DataSource = DtSet;
¿el DtSet tiene datos? si es así, editar la pregunta con el código delGridView1
.MyCommand.TableMappings.Add("Table", "TestTable");
eso no aplica