Solved

foreach loop with conditional statement

Posted on 2014-11-07
5
88 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
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:Tchuki
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 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

22 Experts available now in Live!

Get 1:1 Help Now