Kith
Kith

Reputation: 117

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-

enter image description here

GRN table

enter image description here

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"]);
        }
}

Upvotes: 1

Views: 187

Answers (1)

Ole EH Dufour
Ole EH Dufour

Reputation: 3240

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)");

Upvotes: 3

Related Questions