简体   繁体   中英

C# not liking SQL JOINS

I am trying to compare and build a table comparing two columns(Using LIKE). In two classes(Win32_Printer.name and Win32_PrinterDriver.name).

The only issue is I cannot run any kind of JOIN

string query = string.Format("SELECT * 
FROM Win32_Printer INNER JOIN Win32_PrinterDriver
ON Win32_Printer.Name = Win32_PrinterDriver.Name
WHERE Win32_Printer.Name LIKE '%', Win32_PrinterDriver.Name, '%'"); 

After this is run I get thrown an error:

在此输入图像描述

I think you repeat the join condition. You can go with just

SELECT * 
FROM Win32_Printer 
  INNER JOIN Win32_PrinterDriver ON Win32_Printer.Name = Win32_PrinterDriver.Name

or if you want compare with like:

SELECT * 
FROM Win32_Printer P
  INNER JOIN Win32_PrinterDriver D ON D.Name LIKE '%'+P.Name+'%'
        string query = string.Format("SELECT * FROM Win32_Printer")
        try
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

        ManagementObjectCollection coll = searcher.Get();
        string name = "";
        foreach (ManagementObject printer in coll)
        {
            foreach (PropertyData property in printer.Properties)
            {

                if (property.Name == "Name")
                {
                    name = property.Value.ToString();
                }
                rtxLog.AppendText(property.Name + "-->" + property.Value + "\n");
                if (property.Name == "WorkOffline")
                {
                    string querydriver = string.Format("SELECT * from Win32_PrinterDriver WHERE Name LIKE '%" + name + "%'");
                    ManagementObjectSearcher searcherdriver = new ManagementObjectSearcher(querydriver);
                    ManagementObjectCollection colldriver = searcherdriver.Get();

                    foreach (ManagementObject driver in colldriver)
                    {
                        foreach (PropertyData propertydriver in driver.Properties)
                        {
                            rtxLog.AppendText(propertydriver.Name + "-->" + propertydriver.Value + "\n");
                        }
                    }
                }
                rtxNameLog.AppendText(name + "\n");
            }
            rtxLog.AppendText("\n\n\n\n\n\n\n\n\n\n\n");
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM