Solved

foreach loop with conditional statement

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

815 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

12 Experts available now in Live!

Get 1:1 Help Now