Note that there are some explanatory texts on larger screens.

plurals
  1. POC# - Updating a row using LINQ
    primarykey
    data
    text
    <p>I am in the process of improving a console app and at the moment I cant get it to update rows instead of just creating a new row with the newer information in it.</p> <pre><code>class Program { List&lt;DriveInfo&gt; driveList = DriveInfo.GetDrives().Where(x =&gt; x.IsReady).ToList&lt;DriveInfo&gt;(); //Get all the drive info Server server = new Server(); //Create the server object ServerDrive serverDrives = new ServerDrive(); public static void Main() { Program c = new Program(); c.RealDriveInfo(); c.WriteInToDB(); } public void RealDriveInfo() { //Insert information of one server server.ServerID = 0; //(PK) ID Auto-assigned by SQL server.ServerName = string.Concat(System.Environment.MachineName); //Inserts ServerDrives information. for (int i = 0; i &lt; driveList.Count; i++) { //All Information used in dbo.ServerDrives serverDrives.DriveLetter = driveList[i].Name; serverDrives.TotalSpace = driveList[i].TotalSize; serverDrives.DriveLabel = driveList[i].VolumeLabel; serverDrives.FreeSpace = driveList[i].TotalFreeSpace; serverDrives.DriveType = driveList[i].DriveFormat; server.ServerDrives.Add(serverDrives); } } public void WriteInToDB() { //Add the information to an SQL Database using Linq. DataClasses1DataContext db = new DataClasses1DataContext(@"sqlserver"); db.Servers.InsertOnSubmit(server); db.SubmitChanges(); </code></pre> <p>What I would like it to use to update the information would be the <code>RealDriveInfo()</code> Method so instead of creating new entries it updates the currently stored information by running the method then inserting the information from the method and if needed will enter a new entry instead of simply entering new entries every time it has newer information.</p> <p>At the moment it is running the method, gathering the relevant data then entering it in as a new row in both tables.</p> <p>Any help would be appreciated :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload