bueno ya di con la solucion era tema de ordenar un poco.
Código ASP:
Ver originalprotected void btnUpload_Click(object sender, EventArgs e)
{
Boolean fileOk = false;
string path = string.Concat(Server.MapPath("~/Uploaded Folder/" + FileUpload1.FileName));
if (FileUpload1.HasFile)
{
int fileSize = FileUpload1.PostedFile.ContentLength;
if (fileSize < 420000000)
{
string FileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
string allowwExtension4 = ".xls";
string allowwExtension5 = ".xlsx";
if (FileExtension == allowwExtension4 || FileExtension == allowwExtension5)
{
fileOk = true;
}
}
else
{
fileOk = false;
}
}
if (fileOk)
{
try
{
FileUpload1.PostedFile.SaveAs(path);
// Connection String to Excel Workbook
string excelConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 8.0", path);
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = excelConnectionString;
OleDbCommand command = new OleDbCommand("select * from [hoja1$]", connection);
connection.Open();
//////////////////////////////////////////////////////////////////////////////////////////
int verif_correctas = 0;
int verif_total = 0;
DbDataReader dr_verif = command.ExecuteReader();
if (dr_verif.HasRows)
{
while (dr_verif.Read())
{
if (!(dr_verif["marks"] is DBNull))
{
verif_correctas++;
}
if (!(dr_verif["id"] is DBNull))
{
verif_total++;
}
}
}
dr_verif.Close();
Label2.Text = verif_correctas.ToString();
Label3.Text = verif_total.ToString();
if (verif_correctas == verif_total)
{
// Create DbDataReader to Data Worksheet
DbDataReader dr = command.ExecuteReader();
// SQL Server Connection String
string sqlConnectionString = @"Data Source=.;Initial Catalog=excel;Integrated Security=True";
// Bulk Copy to SQL Server
SqlBulkCopy sqlBulk = new SqlBulkCopy(sqlConnectionString);
//Give your Destination table name
sqlBulk.DestinationTableName = "excel01";
sqlBulk.WriteToServer(dr);
Label1.Text = "Exito";
dr.Close();
connection.Close();
}
else
{
Label1.Text = "Algun dato de la columna 'Marks' no es un numero, debido a esto no se pudo agregar los datos del excel en la base de datos";
}
//////////////////////////////////////////////////////////////////////////////////////////
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
}
else
{
Label1.Text = "No se pudo cargar el archivo excel";
}
}