2

I have a DataTable with the following columns:

  • id
  • msisdn
  • status
  • another_column

And a string[2][n] array (multi dimensional):

{msisdn, status, useless_data} . . .

I need start from 0 to n in string array and search for the msisdn field in data table. And update the status column in the datatable from the string array's status field.

In datatable msisdn is not unique. More than one column may contain sama msisdn twice or more. However in string array msisdn is unique.

What is the fastest way to match this DataTable and String array and do the stuff above?

Any ideas or help would be appreciated.

1
  • 1
    First of this table is geared towards the telecoms industry, hence the "msisdn" field, so im just assuming here but other columns would be StartDate and EndDate (hence the multiple entries), therefore u need the entry with the latest StartDate, EndDate for this entry would most probably be NULL, thats the DataTable status field you need to update specifically, makes the ordering valid in the DataTable, and changes the search. Just a thought. Commented Nov 2, 2009 at 20:28

3 Answers 3

4

First, I would hope that your string array declaration is more like string[n][2] rather than string[2][n]. For the purposes of this answer I'm going to assume that's the case and it's just a typo.

The fastest way is likely with a DataView, though LINQ to DataSets in .NET 3.5 may be just as good. Something like this:

DataView view = new DataView(yourDataTable);
string[][] data = new string[n][2];

view.Sort = "msisdn";

for(int i = 0; i < theArray; i++)
{
    view.RowFilter = "msisdn = '" + data[i][0] + "'";

    foreach(DataRowView row in view)
    {
        row["status"] = data[i][1];
    }
}
Sign up to request clarification or add additional context in comments.

Comments

2

Since the msisdn is unique in the array, you could consider making that array a dictionary keyed by msisdn instead. Iterate through the rows just once and look the key up in the dictionary as you go.

Comments

1

The $100,000 question is whether the data is sorted or can be easily sorted. If one or both of those collections are sorted by msisdn the operation will be much faster: O(n2) for neither sorted, O(n log n) for 1 sorted, O(n) for both.

Of course, the algorithm you use will then vary based on this answer as well, so we'll need to hear a response on that before we can give more detail.

1 Comment

Given that he states that the data is in a DataTable, that would seem to answer all of those questions. However, since the DataView maintains a column index on the sorted column, I don't think that the order of the array will have an effect on filter time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.