This is my coding to upload a excel......
if (RevenueDumpFileUpload.HasFile)
{
string strFilePathOnServer = ConfigurationManager.AppSettings["RevenueDumpFileLocation"];
String sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(strFilePathOnServer) + RevenueDumpFileUpload.FileName + ";Extended Properties=\"Excel 8.0;IMEX=1;HDR=NO;TypeGuessRows=0;ImportMixedTypes=Text\"";
string strPostedFileName = RevenueDumpFileUpload.PostedFile.FileName;
if (strPostedFileName != string.Empty && RevenueDumpFileUpload.PostedFile.ContentLength != 0)
{
//Save-Upload File to server.
RevenueDumpFileUpload.PostedFile.SaveAs(Server.MapPath(strFilePathOnServer) + RevenueDumpFileUpload.FileName);
RevenueDumpFileUpload.FileContent.Dispose();
}
OleDbConnection Exlcon = new OleDbConnection(sConnectionString);
try
{
//Exlcon.Open();
}
catch
{
return;
}
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Owner$]", Exlcon);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
objDataset1.Clear();
objAdapter1.Fill(objDataset1, "XLData");
DataRow rowDel = objDataset1.Tables["XLData"].Rows[0];
objDataset1.Tables["XLData"].Rows.Remove(rowDel);
objDataset1.Tables["XLData"].Columns[0].ColumnName = "Industry";
objDataset1.Tables["XLData"].Columns[1].ColumnName = "Company Name";
objDataset1.Tables["XLData"].Columns[2].ColumnName = "Website";
objDataset1.Tables["XLData"].Columns[3].ColumnName = "Address";
objDataset1.Tables["XLData"].Columns[4].ColumnName = "State";
objDataset1.Tables["XLData"].Columns[5].ColumnName = "Company PhoneNumber";
objDataset1.Tables["XLData"].Columns[6].ColumnName = "Contact Person";
objDataset1.Tables["XLData"].Columns[7].ColumnName = "Title Description";
objDataset1.Tables["XLData"].Columns[8].ColumnName = "Company Size";
objDataset1.Tables["XLData"].Columns[9].ColumnName = "Mail ID";
objDataset1.Tables["XLData"].Columns[10].ColumnName = "Guess MailID";
objDataset1.Tables["XLData"].Columns[11].ColumnName = "Phone No";
objDataset1.Tables["XLData"].Columns[12].ColumnName = "Linked in id";
objDataset1.Tables["XLData"].Columns[13].ColumnName = "Comment";
methodtosave();
}
I am getting the error fill method..."TOO MANY FIELDS UNDEFINED". There are only "14"columns.....