Link to home
Start Free TrialLog in
Avatar of finance_teacher
finance_teacher

asked on

C# -- DataGridView -- TableAdapter COUNT ?

The below two "WORKS" sections works.

How can I change the below "FAILS"
section to have something like
a ".Results > 0" ?
  ** attached shows that
     .Results is not valid
--------------------------------------------------
WORKS #1
                if (vAD_PREPRESS_ID > 0 && Convert.ToBoolean(accountDetailMaintenanceDataGridView.Rows[i].Cells["PREPRESS"].Value) == false)
                {
                    this.accountDetailMaintenanceTableAdapter.Delete_AD_Record(vAD_PREPRESS_ID);
                }
--------------------------------------------------              
WORKS #2
.Has_Designer_Records
SELECT count(im.PDESIGNER)
FROM GML_ITEMMSTR im
Where im.PDESIGNER in
 (
   SELECT
   ad.AM_CID
   FROM GML_ACCTDETL ad
   Where ad.ID = :vAD_DESIGNER_ID
 )
--------------------------------------------------
FAILS  
                if (vAD_PREPRESS_ID > 0 && Convert.ToBoolean(accountDetailMaintenanceDataGridView.Rows[i].Cells["PREPRESS"].Value) == false)
                {
                    if (this.accountDetailMaintenanceTableAdapter.Has_Designer_Records(vAD_DESIGNER_ID).Results > 0)
                    {
                        MessageBox.Show("GML_ITEMMSTR PDESIGNER record exists, cannot delete " + vAD_DESIGNER_ID);
                    }
                    else
                    {
                        this.accountDetailMaintenanceTableAdapter.Delete_AD_Record(vAD_PREPRESS_ID);
                    }
                }
0001.jpg
Avatar of Rakesh Jaimini
Rakesh Jaimini
Flag of India image

try following

if (this.accountDetailMaintenanceTableAdapter.Has_Designer_Records(vAD_DESIGNER_ID).HasValue> 0)
                    {
                        MessageBox.Show("GML_ITEMMSTR PDESIGNER record exists, cannot delete " + vAD_DESIGNER_ID);
                    }
                    else
                    {
                        this.accountDetailMaintenanceTableAdapter.Delete_AD_Record(vAD_PREPRESS_ID);
                    }

Open in new window

slight modification

 if (this.accountDetailMaintenanceTableAdapter.Has_Designer_Records(vAD_DESIGNER_ID).HasValue)
                    {
                        MessageBox.Show("GML_ITEMMSTR PDESIGNER record exists, cannot delete " + vAD_DESIGNER_ID);
                    }
                    else
                    {
                        this.accountDetailMaintenanceTableAdapter.Delete_AD_Record(vAD_PREPRESS_ID);
                    }

Open in new window

Avatar of finance_teacher
finance_teacher

ASKER

Still fails

Example
 1. attached displays
 2. uncheck 10163 & 10170
 3. click "Save"
 4. below 10163 results display "2",
    MessageBox.Show runs
 5. below 10170 results display "0",
    MessageBox.Show runs, but should
    not since results are NOT > 0
---------------------------------------
SELECT count(im.PDESIGNER)
FROM GML_ITEMMSTR im
Where im.PDESIGNER in
 (
   SELECT
   ad.AM_CID
   FROM GML_ACCTDETL ad
   Where ad.ID = :vAD_DESIGNER_ID
 )
---------------------------------------
0001.jpg
Avatar of teebon
Hi finance_teacher,

Change your WORKS #2 by adding ISNULL checking:

.Has_Designer_Records
SELECT ISNULL(count(im.PDESIGNER), 0)
FROM GML_ITEMMSTR im
Where im.PDESIGNER in
 (
   SELECT
   ad.AM_CID
   FROM GML_ACCTDETL ad
   Where ad.ID = :vAD_DESIGNER_ID
 )

Then you can use the following line:

 if (this.accountDetailMaintenanceTableAdapter.Has_Designer_Records(vAD_DESIGNER_ID).Value > 0)
ASKER CERTIFIED SOLUTION
Avatar of teebon
teebon
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The below seems to work without
this.accountDetailMaintenanceTableAdapter.Has_Designer_Records(vAD_DESIGNER_ID).HasValue
Is the above line really needed ?
---------------------------------------------------------------------------------------
                if (vAD_DESIGNER_ID > 0 && Convert.ToBoolean(accountDetailMaintenanceDataGridView.Rows[i].Cells["DESIGNER"].Value) == false)
                {
                   if (this.accountDetailMaintenanceTableAdapter.Has_Designer_Records(vAD_DESIGNER_ID).Value > 0)
                    {
                        MessageBox.Show("GML_ITEMMSTR PDESIGNER record exists, cannot delete " + vAD_DESIGNER_ID);
                    }
                    else
                    {
                        this.accountDetailMaintenanceTableAdapter.Delete_AD_Record(vAD_DESIGNER_ID);
                    }
                }
Hi finance_teacher,

It will not be needed as long as the .Value will never contain NULL.