cartographer.ElectorateImporter.ParseStateResultsXLS C# (CSharp) Méthode

ParseStateResultsXLS() public méthode

public ParseStateResultsXLS ( string a_filename ) : void
a_filename string
Résultat void
        public void ParseStateResultsXLS(string a_filename)
        {
            string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + a_filename + ";Extended Properties=\"Excel 8.0;HDR=YES;\"";

            OleDbConnection xlsConnection = new OleDbConnection(connectionString);
            xlsConnection.Open();

            //OleDbCommand commandtest = new OleDbCommand("SELECT * FROM [2004 Election$]", connection);
            OleDbDataAdapter _allData = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", xlsConnection);
            DataSet ds = new DataSet();
            _allData.Fill(ds);
            var table = ds.Tables[0];
            int i = 1;

            OleDbConnection _connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data/db.mdb"); //!testing
            foreach (DataRow row in table.Rows)
            {
                try
                {
                    _connection.Open();
                    string command = "UPDATE StateElectorate SET WinningParty='" + row.ItemArray[4] + "' WHERE ElectorateName='" + row.ItemArray[1] + "';";
                    OleDbCommand updateCommand = new OleDbCommand(command, _connection);
                    updateCommand.ExecuteNonQuery();
                }
                finally
                {
                    _connection.Close();
                }
                i++;

            }
        }