• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 695
  • Last Modified:

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
0
finance_teacher
Asked:
finance_teacher
  • 3
  • 2
  • 2
1 Solution
 
Rakesh JaiminiCommented:
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

0
 
Rakesh JaiminiCommented:
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

0
 
finance_teacherAuthor Commented:
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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
teebonCommented:
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)
0
 
teebonCommented:
Alternatively, you can also use the following line without needing to change your WORKS #2:
if (this.accountDetailMaintenanceTableAdapter.Has_Designer_Records(vAD_DESIGNER_ID).HasValue 
&& this.accountDetailMaintenanceTableAdapter.Has_Designer_Records(vAD_DESIGNER_ID).Value > 0)

Open in new window

0
 
finance_teacherAuthor Commented:
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);
                    }
                }
0
 
teebonCommented:
Hi finance_teacher,

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now