private void btnImport_Click(object sender, EventArgs e) { string csvPath = CSVData.OpenCSV(); if (csvPath != "") { try { using (this.auditConn = this.AuditDB.GetSQLConnection()) { int addedRows = 0; DataTable importDt = CSVData.ReadCSVToDataTable(csvPath); foreach (DataRow row in importDt.Rows) { // Prepare the SQL query string software_name = row["Name"].ToString(); SqlCommand findItem = new SqlCommand("GetSoftwareItem", this.auditConn); findItem.CommandType = CommandType.StoredProcedure; SqlParameter itemName = new SqlParameter("@name", SqlDbType.NVarChar, 250); itemName.Value = software_name; findItem.Parameters.Add(itemName); // Execute the query to find if a software already existed in the list string findName = null; findName = Convert.ToString(findItem.ExecuteScalar()); // Add a new row only if one did not exist before if (findName == "") { SqlCommand insertItem = new SqlCommand("InsertIntoSoftwareItems", this.auditConn); insertItem.CommandType = CommandType.StoredProcedure; SqlParameter softwareName = new SqlParameter("@Name", SqlDbType.NVarChar, 250); softwareName.Value = software_name; insertItem.Parameters.Add(softwareName); SqlParameter vendorName = new SqlParameter("@Vendor", SqlDbType.NVarChar, 100); vendorName.Value = row["Vendor"].ToString(); insertItem.Parameters.Add(vendorName); insertItem.ExecuteNonQuery(); addedRows++; } } if (addedRows > 0) { MessageBox.Show(addedRows + " new software items added", "New items"); } else { MessageBox.Show("No new software items added", "No items added"); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Could not parse M-Files CSV export"); } } else { MessageBox.Show("Error in opening M-Files CSV export!"); } }