?
Solved

C# -- WinForms "TableAdapter" result checking ?

Posted on 2010-01-12
3
Medium Priority
?
510 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

764 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