?
Solved

i need to run over my DB table and check if the continuity are o.k

Posted on 2006-07-06
15
Medium Priority
?
210 Views
Last Modified: 2010-04-16
hi there ,

i have an order table in my db i want to run over the orderNum row
and chesk the continuity if something worng and there is duplicity or lack or miss number i want to poll out the
number or the relative number into a listBox

i am on SQl 2000 db WinForm pro on c# 1.1.

thanks all ....
0
Comment
Question by:Tech_Men
[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
  • 8
  • 7
15 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17050409
The description of the problem is not clear enough to help.

Bob
0
 

Author Comment

by:Tech_Men
ID: 17050800
i have an order table in my DB

orderID
1
2
3
4
-
6
7
7
8
i want to know that in my table the ordernum=5 are miising
i want to know that order num=7 haz 2 orders in the same number i need to chek the succession  in my DB
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17051241
using System.Collections;
using System.Data;
using System.Text;

...

  public bool ValidateOrders(DataTable table, out string errors)
  {
    Hashtable validation = new Hashtable();

    StringBuilder errorBuilder = new StringBuilder();
    foreach (DataRow row in table.Rows)
    {
      string orderID = row["orderID"].ToString();

      if (validation.ContainsKey(orderID))
      {
        errorBuilder.Append("Duplicate order:  " + orderID + "\r\n");
      }
      else if (orderID == "-")
      {
        errorBuilder.Append("Missing order:  " + orderID + "\r\n");
      }
      else
      {
        validation.Add(orderID, orderID);
      }
    }

    errors = errorBuilder.ToString();

    return (errors.Length == 0);
  }

}

Bob
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Tech_Men
ID: 17054177
its work fine but the miising part are not working
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17054557
Can you tell me what it is not doing?  Exceptions?

Bob
0
 

Author Comment

by:Tech_Men
ID: 17055028
there is no exsption
but he dosent visit in this code

      else if (HesID == "-")
                              {
                                    errorBuilder.Append("Missing invoice:  " + HesID +" "+"\r\n\n");
                                    listBox1.Items.Add(errorBuilder.ToString());
                              }

even that i have a missing order
1
2
-
4

thanks ...BOb

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17055161
Can you show me the complete code of what you came up with, please?

Bob
0
 

Author Comment

by:Tech_Men
ID: 17056758
sure
foreach (DataRow row in table.Rows)
                  {
                        bool temp = bool.Parse(row["OutOrIn"].ToString());

                        if(temp==true)
                        {
                              string HesID = row["HasbonitNum"].ToString();

                              if (validation.ContainsKey(HesID))
                              {
                                    errorBuilder.Append("Duplicate invoice:  " + HesID + " " +"\r\n\n");
                                    listBox1.Items.Add(errorBuilder.ToString());
                              }
                              else if (HesID == "-")
                              {
                                    errorBuilder.Append("Missing invoice:  " + HesID +" "+"\r\n\n");
                                    listBox1.Items.Add(errorBuilder.ToString());
                              }
                              else
                              {
                                    validation.Add(HesID, HesID);

                              }
                        }
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17057535
I got to thinking about something, and it seems like a silly assumption that I made.  Are you saying that a missing invoice is a '-' or a null/empty string?  

If so, then you need something like this:

                    else if (HesID.Length == 0)
 
Bob
0
 

Author Comment

by:Tech_Men
ID: 17060547
not working
i the table there is orders
1
2
4

3 is deleted
there is no row in 3

thanks ...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17062355
Try a little different approach with a SortedList instead of a Hashtable:

using System.Collections;
using System.Data;
using System.Text;

...

  public void ValidateOrders(DataTable table, out string errors)
  {

    // Clear the errors.
    errors = "";

    // Collect all the IDs
    SortedList validation = new SortedList();

    // Get all the table rows, looking for duplicate invoice numbers.
    foreach (DataRow row in table.Rows)
    {
      bool outOrIn = bool.Parse(row["OutOrIn"].ToString());

      if (outOrIn)
      {
        string HesID = row["HasbonitNum"].ToString();

        if (validation.ContainsKey(HesID))
        {
          listBox1.Items.Add("Duplicate invoice:  " + HesID);
        }
        else
        {
          validation.Add(HesID, HesID);
        }
      }

    }

    // Look at the difference between two invoice numbers.  Any value
    // greater than 1 indicates a missing invoice number.
    string current = "";
    foreach (string val in validation.Values)
    {
      if (current.Length != 0 && (int.Parse(val) - int.Parse(current) > 1))
      {
        listBox1.Items.Add("Missing invoice:  " + current.ToString());
      }
      // Store the current ID to compare to the next ID
      current = val;
    }

  }

Bob
0
 

Author Comment

by:Tech_Men
ID: 17064118
its not working
i dont get any worning abhot the duplicated  invoice

and there is a problem whit the missing invoice
like :
1
2
4

i get meesage that number 2 is misiing insted of 3 ...

sooryyy .... i hope that every thing works....


0
 

Author Comment

by:Tech_Men
ID: 17064148
soooryyy

the duplicated is working fine +++
only this :
and there is a problem whit the missing invoice
like :
1
2
4

i get meesage that number 2 is misiing insted of 3 ...

0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1600 total points
ID: 17064980
Sorry, there wasn't any way for me to test that code, so I left that up to you:

    listBox1.Items.Add("Missing invoice:  " + val.ToString());

The 'current' value is the previous element, and 'val' is the current.  I think those are misnamed variables--in retrospect they should be 'previous' and 'current' instead of 'current' and 'val'.

Bob
0
 

Author Comment

by:Tech_Men
ID: 17068913
thanks u Very mush ..........Love u :))
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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

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