?
Solved

C# -- WinForms "TableAdapter" result checking ?

Posted on 2010-01-12
3
Medium Priority
?
516 Views
Last Modified: 2013-12-17
How can I change the below so it works ?
-------------------------------------------------------
        private void SetPermissions()
        {
            this.getRoleIDTableAdapter1.GetData(2); // returns 6, 8, and 3

            //foreach (DataRow row in something)
            //{
            //    if (role.ID != 3) // if one of the above results is NOT 3
                                    // one of the above results is 3,
                                    // therefore this would not get run
            //    {
            //          transAllergensToolStripMenuItem.Visible = false;
            //    }
            //    if (role.ID != 2) // if one of the above results is NOT 2
                                    // none of the above results is 2,
                                    // therefore this would get run and make
                                    // materialSpecsToolStripMenuItem.Visible = false;
            //    {
            //        materialSpecsToolStripMenuItem.Visible = false;
            //    }
            //}            
        }
0
Comment
Question by:finance_teacher
  • 2
3 Comments
 

Author Comment

by:finance_teacher
ID: 26298635
I also tried the below, but it failed, saying
that dRow.ROLE_ID does not exists.

Please help.
---------------------------------------------------
        private void SetPermissions()
        {
            foreach (DataRow dRow in getRoleIDTableAdapter1.GetData(2).Rows) // returns 6, 8, and 3
            {
                if (dRow.ROLE_ID != 3) // if one of the above results is NOT 3
                {
                      transAllergensToolStripMenuItem.Visible = false;
                }
                if (dRow.ROLE_ID != 2) // if one of the above results is NOT 2
                {
                    materialSpecsToolStripMenuItem.Visible = false;
                }
            }            
        }
0
 
LVL 10

Accepted Solution

by:
RameshS earned 2000 total points
ID: 26300159
Try this.

 private void SetPermissions()
        {
            foreach (DataRow dRow in getRoleIDTableAdapter1.GetData(2).Rows) // returns 6, 8, and 3
            {
                int roleID = (int) dRow["ROLE_ID"] ;

                if ( roleID   != 3) // if one of the above results is NOT 3
                {
                      transAllergensToolStripMenuItem.Visible = false;
                }
                if (roleID  != 2) // if one of the above results is NOT 2
                {
                    materialSpecsToolStripMenuItem.Visible = false;
                }
            }            
        }
0
 

Author Comment

by:finance_teacher
ID: 26303412
int roleID = (int)dRow["ROLE_ID"];
gave a "Specified cast is not valid" ERROR,
 therefore I did the below.


        private void SetPermissions()
        {
            foreach (DataRow dRow in getRoleIDTableAdapter1.GetData(2).Rows) // returns 6, 8, and 3
            {
                int roleID = Convert.ToInt32(dRow["ROLE_ID"]);

                if (roleID != 3) // if one of the above results is NOT 3
                {
                    transAllergensToolStripMenuItem.Visible = false;
                }
                if (roleID != 2) // if one of the above results is NOT 2
                {
                    materialSpecsToolStripMenuItem.Visible = false;
                }
            }
        }
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Integration Management Part 2
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question