Solved

foreach loop with conditional statement

Posted on 2014-11-07
5
84 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
  • 3
5 Comments
 

Accepted Solution

by:
desiredforsome earned 0 total points
Comment Utility
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 32

Expert Comment

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

-saige-
0
 

Author Comment

by:desiredforsome
Comment Utility
no i am not
0
 
LVL 14

Expert Comment

by:Tchuki
Comment Utility
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
Comment Utility
Went another route. This was not wokring could not get to work properly. THanks though.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now