Solved

foreach loop with conditional statement

Posted on 2014-11-07
5
92 Views
Last Modified: 2014-11-30
Hello All,

I am using the code below to run a sql query against a db and create a notification message for each record that has a "0" in its 8th place in sql. I want it to show me the value of Borrower for each statement in my notification but does not seem to be working. What am I doing wrong?

 private void populatelist()
        {
            dataGridView1.Rows.Clear();
            SqlConnection conn = new SqlConnection();
            
            SqlCommand command = this.conn.CreateCommand();
            command.CommandText = "SELECT * FROM ONLINEPORTAL where clear ='0'";
            this.conn.Open();
            SqlDataReader sqlDataReader = command.ExecuteReader();
            while (sqlDataReader.Read())
            {
                if (sqlDataReader[8].ToString() == "0")
                {

                    PopupNotifier alert = new PopupNotifier();
                    alert.TitleText = "New Attachments Available";
                    alert.ContentText = sqlDataReader[3].ToString() + " - " + sqlDataReader[1].ToString();
                    alert.Popup();
                }
                this.BORROWER = sqlDataReader[3].ToString() + " - " + sqlDataReader[1].ToString();
                this.XREFID1 = sqlDataReader[0].ToString();
                this.LOCATION1 = sqlDataReader[2].ToString();
                this.NAME1 = sqlDataReader[3].ToString();
                this.notified = sqlDataReader[8].ToString();
                this.DOCTYPE = sqlDataReader[1].ToString();
                

                this.dataGridView1.Rows.Add((object)this.BORROWER, (object)this.LOCATION1, (object)this.XREFID1, (object)this.NAME1, (object)this.DOCTYPE, (object)this.notified);
              
                //if (notified == "0")
                //{
                //    PopupNotifier alert = new PopupNotifier();
                //    alert.TitleText = "New Attachments Available";
                //    alert.ContentText = BORROWER;
                //    alert.Popup();
                //}
                //else
                //{

                //}
            }
            sqlDataReader.NextResult();
            this.conn.Close();
            RESIZEGRID();

Open in new window

0
Comment
Question by:desiredforsome
[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
  • 3
5 Comments
 

Accepted Solution

by:
desiredforsome earned 0 total points
ID: 40429181
I actually see the issue and it is that the notifiation boxes are all popping up at the same time over eachother. Is there a way to delay it so that it waits lets say 1 second between each popup?
0
 
LVL 33

Expert Comment

by:it_saige
ID: 40429185
Are you running this process on a thread that is seperate from your UI thread?

-saige-
0
 

Author Comment

by:desiredforsome
ID: 40429194
no i am not
0
 
LVL 14

Expert Comment

by:Vel Eous
ID: 40429695
Ideally you don't want to be performing application logic within your database operations.  Really you want to make your database call for the data you want, return the data (if applicable) and perform your logic on the returned data.

1.

You want to keep database access time as short as possible

2.

Separation of Concerns
I would recommend you retrieve the data you want from the database to a collection of some sort (list, dictionary, queue, stack etc.) then perform your processing from there.  You could make a ProcessBorrowerCollection method which enumerates the collection displaying a notification for each item.  Within this method you can use any mechanism you want to 'stagger' the notifications (I don't know the details of your PopupNotifier so can't advise further really).

Additionally it_saige touched on this with his/her comment, run your DB query and notification processing on a separate thread to your UI thread.  You don't want your UI hanging and becoming unresponsive due to long running processes.
0
 

Author Closing Comment

by:desiredforsome
ID: 40472366
Went another route. This was not wokring could not get to work properly. THanks though.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# MVC Insert Multiple Row into DB 2 62
itextsharp with c# 3 18
Problem to Office 1 42
Powershell form - Anchor a button to a dynamically sized groupbox 2 44
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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