private void button1_Click(object sender, EventArgs e) { OpenFileDialog of = new OpenFileDialog(); of.Filter = "Excel 2007 Files|*.xlsx"; of.Title = "Open Excel 2007 Files"; DialogResult dr = new DialogResult(); dr = of.ShowDialog(); if (dr == DialogResult.Cancel) return; string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source= " + of.FileName + " ;Extended Properties=\"Excel 12.0;HDR=No;\""; string strSQL = "SELECT * FROM [QueryExportToExcel$]"; OleDbConnection excelConnection = new OleDbConnection(connectionString); excelConnection.Open(); OleDbCommand dbCommand = new OleDbCommand(strSQL, excelConnection); OleDbDataAdapter dataAdapter = new OleDbDataAdapter(dbCommand); DataTable dTable = new DataTable(); dataAdapter.Fill(dTable); DataGridView1.DataSource = dTable; int ram = 0; int cpu = 0; int hard = 0; int monitor = 0; for (int i = 0; i < dTable.Rows.Count; i++) { string s=dTable.Rows[i][0].ToString().Trim(); if (s.Contains ( "ram")) { // dTable.Rows[i][1] is Number of piece ram += Convert.ToInt32(dTable.Rows[i][1]) * 5; } if (s.Contains( "cpu")) { cpu += Convert.ToInt32(dTable.Rows[i][1]) * 3; } if (s.Contains ( "hard")) { hard += Convert.ToInt32(dTable.Rows[i][1]) * 5; } if (s.Contains ( "monitor")) { monitor += Convert.ToInt32(dTable.Rows[i][1]) * 5; } } label1.Text ="Score:"+ (ram + cpu + hard + monitor).ToString(); dTable.Dispose(); dataAdapter.Dispose(); dbCommand.Dispose(); excelConnection.Close(); excelConnection.Dispose(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)