简体   繁体   中英

How to check if a record exists in the SQL Server database C# winform?

My windows form application is about Book Store. I would like to display PO numbers in a ComboBox which didn't have create a Good Received Note.

This is the structure of this two tables.

PO Table-

在此输入图像描述

GRN table

在此输入图像描述

How to change following code?

 public void fillPOcombo()
 {
        DynamicConnection con = new DynamicConnection();
        con.mysqlconnection();
        con.sqlquery("select PO_No from TBL_PO");
        con.dataread();

        while (con.datareader.Read())
        {
            cmbpono.Items.Add((int)con.datareader["PO_NO"]);
        }
}

I would say as follows :

Change

con.sqlquery("select PO_No from TBL_PO");

to

con.sqlquery("select PO_No from TBL_PO where PO_No not in (select PO_No from GRN)");

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