Solved

foreach loop with conditional statement

Posted on 2014-11-07
5
93 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 34

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

739 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