Import Data from EXCEL TO SQL
|
using Excel = Microsoft.Office.Interop.Excel;
string Path = @"f:\ACC_LEDGER_TROYEE.xls";
Excel.Application app = new Excel.Application();
Excel.Workbook workBook = app.Workbooks.Open(Path, 0, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
Excel.Worksheet workSheet = (Excel.Worksheet)workBook.ActiveSheet;
int index = 0;
object rowIndex = 2;
object colIndex1 = 1;
object colIndex2 = 2;
object colIndex3 = 3;
try
{
while (((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value != null)
{
rowIndex = 2 + index;
//mpristrLedgerSerialNo = ((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value.ToString();
mpristrLedgerName = ((Excel.Range)workSheet.Cells[rowIndex, colIndex2]).Value.ToString();
liLedgerPartyType = Convert .ToInt16 (((Excel.Range)workSheet.Cells[rowIndex, colIndex3]).Value);
mpristrLedgerCurrencySymbol = ((Excel.Range)workSheet.Cells[rowIndex, colIndex4]).Value.ToString();
clsOperationGateway.mpubstaiInsertIntoAccLedger(tbleAccLedger);
clsOperationGateway.mpubstaiUpdateAccLedgerForExcel(mpristrLedgerName, mpristrLedgerCodeTemp, mpristrLedgerCode, mpristrLedgerCurrencySymbol, mpristrLedgerGroupCode, mpridblOpeningBalance, mpridblFCOpeningBalance, mpridblClosingBalance, mpridblOnAccountValue, mpridblDebit, mpridblCredit, mpridblCreditLimit, mpridblCreditPeriod, mpristrAddress1, mpristrCountry, mpristrCity, mpristrPostal, mpristrFax, mpristrTelephone, mpristrMobile, mpristrEmailAddress, mpristrContactPer, mpriiCostCentreStatus, mpriiPayroll, mpriiEffectInventory, mpriiLedgerStatus, mpristrComments, mpristrLedgerInsertDate);
index++;
}
}
catch (Exception ex)
{
app.Quit();
Console.WriteLine(ex.Message);
}
MessageBox.Show("Successfully Imported...........");
}
Post a Comment
Oops!
The words you entered did not match the given text. Please try again.
Oops!
Oops, you forgot something.