public void ImportDataFromExcelEquity() { string excelFilePath = "C:/Users/ahksysuser06/Desktop/EDISData/International_Equity_Daily_Closing_Price_20131211.xlsx"; // make sure your sheet name is correct, here sheet name is sheet1, so you can change the sheet name if have different string excelQuery = "select SecId,Name,Symbol from [Sheet1$]"; try { string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFilePath + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;'"; OleDbConnection oleConn = new OleDbConnection(excelConnectionString); oleConn.Open(); OleDbDataReader oleReader = new OleDbCommand(excelQuery, oleConn).ExecuteReader(); //while (oleReader.Read()) //{ // Domain.Portfolio.AggregateRoots.Asset.Equity equity = new AustralianEquity(edisRepo) // { // Name = oleReader.GetString(1), // Sector = oleReader.GetString(0), // Ticker = oleReader.GetString(2), // EquityType = EquityTypes.AustralianEquity, // }; // edisRepo.InsertEquityData(equity); //} while (oleReader.Read()) { Domain.Portfolio.AggregateRoots.Asset.Equity equity = new InternationalEquity(edisRepo) { Name = oleReader.GetString(1), Sector = oleReader.GetString(0), Ticker = oleReader.GetString(2), EquityType = EquityTypes.InternationalEquity, }; edisRepo.InsertEquityData(equity); } oleReader.Close(); oleConn.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
void caricaDaDb() { string sconn; sconn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb"; OleDbConnection conn = new OleDbConnection(sconn); try { conn.Open(); N_NODI = getint32("SELECT valore FROM parametri WHERE parametro='n' ", 0, conn); settaNnodi(N_NODI); m = getint32("SELECT valore FROM parametri WHERE parametro='m' ", 0, conn); //leggo nodi OleDbDataReader myreader = new OleDbCommand("select x,y,nome from nodi", conn).ExecuteReader(); for (int i = 0; i < N_NODI; i++) { nodi[i].x = nodi[i].y = 0; archi[i] = new ArrayList(); d[i] = new ArrayList(); } while (myreader.Read()) { int x; int y; int nome; //int a, b, c; //myreader.Read(); x = myreader.GetInt32(0); y = myreader.GetInt32(1); nome = Convert.ToInt32(myreader.GetString(2)); nodi[nome].x = x; nodi[nome].y = y; nodi[nome].name = Convert.ToString(nome); archi[nome] = new ArrayList(); d[nome] = new ArrayList(); } //leggo archi myreader = new OleDbCommand("select x,y,dist from archi", conn).ExecuteReader(); //for (int j = 0; j < m; j++) // per ogni arco... while (myreader.Read()) { int from; int dest; int dist; //myreader.Read(); from = myreader.GetInt32(0); dest = myreader.GetInt32(1); dist = myreader.GetInt32(2); //aggiungo arco if (archi[from] == null) archi[from] = new ArrayList(); if (d[from] == null) d[from] = new ArrayList(); archi[from].Add(dest); d[from].Add(dist); } DrawGraph(); conn.Close(); } catch (OleDbException e) { MessageBox.Show("Errore DB" + e.Message); } }