Solved

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

Posted on 2006-07-06
15
204 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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