TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Nagarjuna Naga
NA
53
7.6k
want to update the data in excel to db.but small change
Nov 3 2016 8:01 AM
i am uploading excel sheet
city
categoryname
metadescription
karaikudi
belts
Discover the hottest trends in leather, designer belts at Basics to keep up with you! Choosfrom the brand’s range and stay stylish in every season. Get yours at Karaikudi's best men's accessories store, Basics near you.
karaikudi
blazers
Sport the sharpest, trendiest men's blazers f roBasics. The blazers add the perfect finish to formal and casual outfits, ensuring you are in vogue! Get yours at Karaikudi's best men's clothing store, Basics near you.
like that columname and its description should save in database
my code::
public ActionResult categoryimp()
{
_Workbook workBook = null;
_Worksheet workSheet = null;
Range cellsRange = null;
Range columnRange = null;
Range rowRange = null;
int numberOfColumns = 0;
int numberOfRows = 0;
var excelApp = new Application();
List<Categorydescription> obj = new List<Categorydescription>();
List<Categorydescription> items = new List<Categorydescription>();
try
{
workBook = excelApp.Workbooks.Open("D:/excelnew", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
workSheet = (Worksheet)workBook.Worksheets.get_Item(1);
cellsRange = workSheet.Cells;
columnRange = cellsRange.Columns;
rowRange = cellsRange.Rows;
numberOfColumns = columnRange.Count;
numberOfRows = rowRange.Count;
Range objRange = null;
object[] data = null;
int totalColumns = workSheet.UsedRange.Cells.Columns.Count + 1;
//Iterating from row 2 because first row contains HeaderNames
Categorydescription item = new Categorydescription();
for (int row = 2; row < workSheet.UsedRange.Cells.Rows.Count; row++)
{
item = new Categorydescription();
data = new object[totalColumns - 1];
for (int col = 1; col < totalColumns; col++)
{
objRange = workSheet.Cells[row, col];
if (objRange.MergeCells)
{
data[col - 1] = Convert.ToString(((Range)objRange.MergeArea[1, 1]).Text).Trim();
}
else
{
data[col - 1] = Convert.ToString(objRange.Text).Trim();
}
if (col == 1)
{
item.city= Convert.ToString(objRange.Text).Trim();
}
if (col == 2)
{
item.belts= Convert.ToString(objRange.Text).Trim();
}
if (col == 3)
{
item.Metadescription = Convert.ToString(objRange.Text).Trim();
}
}
items.Add(item);
}
string s = String.Format(
"There are {0} columns and {1} rows in the Worksheet",
numberOfColumns, numberOfRows);
}
finally
{
}
CategorydescDataContext db = new CategorydescDataContext();
db.Categorydescriptions.InsertAllOnSubmit(items);
db.SubmitChanges();
return View();
}
}
}
Reply
Answers (
1
)
Gallery with album
'Microsoft.ACE.OLEDB.12.0' provider is not registered