Solved

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

Posted on 2006-07-06
15
200 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
  • 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
 

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

 

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

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

Title # Comments Views Activity
Loop not working 29 47
VB.Net How to Exit Sub - Exit Form??? 5 51
Help with C#, MVC, razor. 6 23
WCF Service Application cannot connect from TCP terminal 1 14
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…
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

896 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