public void InsertMonitor(MonitorData data)
 {
     try
     {
         sqlConnection.Open();
         SqlCommand sqlCommand = new SqlCommand("INSERT INTO Monitor(monitorModel, monitorSerial, monitorVendor, attachedPC) " +
                                                "VALUES('" + data.modelM + "','" + data.serialNumberM + "','" + data.vendorM + "','" + data.attachedPC + "')"
                                                , sqlConnection);
         sqlCommand.ExecuteNonQuery();
     }
     catch (SqlException e)
     {
         WriteToFile("Sql error from insertMonitor method" + e.Message);
     }
     finally
     {
         sqlConnection.Close();
     }
 }
        private static MonitorData setMonitorData(string serial)
        {
            MonitorData md = new MonitorData();
            //add to database
            Database d = new Database();

            try
            {
                //this queries the information of all available monitors
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\WMI", "SELECT * FROM WmiMonitorID");
                foreach (ManagementObject obj in searcher.Get())
                {
                    foreach (PropertyData p in obj.Properties)
                    {
                        if (p.Value != null)
                        {
                            if (p.Value.GetType().ToString().Equals("System.UInt16[]"))
                            {
                                switch (p.Name)
                                {
                                case "ManufacturerName":
                                {
                                    md.vendorM = getString((UInt16[])p.Value);
                                    break;
                                }

                                case "SerialNumberID":
                                {
                                    md.serialNumberM = getString((UInt16[])p.Value);
                                    break;
                                }

                                case "UserFriendlyName":
                                {
                                    md.modelM = getString((UInt16[])p.Value);
                                    break;
                                }
                                }
                            }
                        }
                        else if (p.Value == null)
                        {
                            if (!d.verifyMonitor(md.serialNumberM))
                            {
                                md.attachedPC    = serial;
                                md.attachedPC    = " " + serial;
                                md.modelM        = "Check";
                                md.serialNumberM = "The";
                                md.vendorM       = "Monitor";
                                d.InsertMonitor(md);
                            }
                        }
                    }

                    /*if (md.modelM != null)
                     * {
                     *  if (!d.verifyMonitor(md.serialNumberM))
                     *  {
                     *      md.attachedPC = serial;
                     *      d.insertMonitor(md);
                     *  }
                     * }*/
                }
            }
            catch (Exception e)
            {
                WriteToFile("Exception thrown in setMonitor " + e.Message);
                d.InsertMonitor(md);
            }

            return(md);
        }