public void UpdateDiscs_HardCodingDiscColumns_ActuallyUpdateDiscs() { string dbLocation = @"c:\temp\Files on Dvd.accdb"; AccessRetriever myRetriever = new AccessRetriever(dbLocation); DataSet dataSet = myRetriever.GetDiscs(); DataRow newDisc = dataSet.Tables[0].NewRow(); newDisc["DiscName"] = "TestDisc22"; newDisc["Wallet"] = 1; newDisc["Notes"] = "I hope this works22"; dataSet.Tables[0].Rows.Add(newDisc); myRetriever.UpdateDiscs(dataSet); Console.WriteLine("Debug this line"); }
public int GetDiscIdByName(string discName) { AccessRetriever retriever = new AccessRetriever(DatabasePath); int discId = -1; try { DataSet dataSet = retriever.GetDiscs(); DataTable discsTable = dataSet.Tables[0]; DataRow[] selectedDiscsRows = discsTable.Select($"DiscName = '{discName}'"); string discIdStr = selectedDiscsRows[0]["ID"].ToString(); bool isInt = int.TryParse(discIdStr, out discId); } catch (Exception e) { Log.Error(e, "Could not retrieve Disc {0}", discName); } return(discId); }
public void AddDisc(DvdFolderToImport dvd) { AccessRetriever retriever = new AccessRetriever(DatabasePath); try { DataSet dataSet = retriever.GetDiscs(); DataRow newDisc = dataSet.Tables[0].NewRow(); newDisc["DiscName"] = dvd.DiscName; newDisc["Wallet"] = dvd.WalletType; newDisc["Notes"] = dvd.Notes; dataSet.Tables[0].Rows.Add(newDisc); retriever.UpdateDiscs(dataSet); } catch (Exception e) { Log.Error(e, "Error adding disc {0} to database", dvd.DiscName); } }
public int Add(DiscLocalDto discDto) { AccessRetriever retriever = new AccessRetriever(databasePath); DataSet dataSet; int? id = 0; try { dataSet = retriever.GetDiscs(); } catch (Exception e) { Log.Error(e, "Could not retrieve discs from database"); throw new ArgumentException("Could not retrieve discs from database", e); } DataTable discsTable = dataSet.Tables[0]; PopulateDiscsFromDatabase(discsTable); if (discs.Any(d => d.DiscName == discDto.DiscName)) { Log.Error("Disc {0} already exists in database", discDto.DiscName); throw new ArgumentOutOfRangeException(discDto.DiscName, "Disc name already exists in database!"); } else { DataRow newRow = discsTable.NewRow(); newRow["DiscName"] = discDto.DiscName; newRow["Wallet"] = discDto.Wallet; newRow["Notes"] = discDto.Notes; // newRow[2] = 1; // this is supposed to be Performer Type. Can use the column number instead discsTable.Rows.Add(newRow); var changes = dataSet.GetChanges(); id = retriever.UpdateDiscs(dataSet); if (id is null) { throw new InvalidOperationException("New DiscId is null. Check Access DB to see if it was entered."); } else { Log.Information("Added Disc {0} to database with ID {1}", discDto.DiscName, id); } } return((int)id); }