vb.Net loop through Dataset.Table(0)

I have a dataset being returned from SQL Server into my web form

It has a column  called BatchNumber that can be from 1 to 1000 rows

I also have a comma seperated string
strMyList = "1,3,5,7"

I would like to remove from strMyList any value not in the "longer list"

So that if the dataset does not have BatchNumber 3 then
strMyList would = "1,5,7"
Larry Bristersr. DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dorababu MSenior Software EngineerCommented:
Can you explain more clearly may be by sending some screen shots of input and output
ste5anSenior DeveloperCommented:
It would be much more efficient to do this on the server.. to reduce data round-trips. E.g.

        BatchNumber INT

INSERT INTO @Batches ( BatchNumber )
VALUES ( 1 ) ,
       ( 2 ) ,
       ( 3 ) ,
       ( 4 );

DECLARE @Parameter VARCHAR(MAX) = '1,3,5,7';

WITH XmlData
AS ( SELECT CAST('<id>' + REPLACE(@Parameter, ',', '</id><id>') + '</id>' AS XML) AS XmlData ) ,
AS ( SELECT A.id.value('.', 'INT') AS id
     FROM   XmlData XD
            CROSS APPLY XD.XmlData.nodes('id') A(id) ) ,
     FROM   IdList IL
     SELECT B.BatchNumber
     FROM   @Batches B )
                 FROM     ResultData RD
                 ORDER BY RD.id
                 FOR XML PATH('')) ,
             1 ,
             2 ,
             '') AS ResultString;

Open in new window

Where @Parameter is the value you pass to an appropriate stored procedure based on the above SELECT statement.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ste5anSenior DeveloperCommented:
btw, the VB approach would be simply looping over your dataset, e.g. something like

ids = "," & Replace(ids, " ", "") & ","
For Each Row As DataRow in SomeTable.Rows ' However you Dataset/Table structure is named
  ids = Replace(ids, "," & Row[BatchNumber], "")

Open in new window

Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
based on my understanding for the requirement and referring to sample of Stefan in ID: 42431385, shouldn't that INTERSECT should be used instead of EXCEPT?


INSERT INTO @Batches ( BatchNumber )
VALUES ( 1 ) ,
       ( 5 ) ,
       ( 7 ) ,
       ( 9 );

DECLARE @Parameter VARCHAR(MAX) = '1,3,5,7';

Open in new window

ste5anSenior DeveloperCommented:
@Ryan, indeed.. misinterpret the OP's requirement.
Larry Bristersr. DeveloperAuthor Commented:
Sorry for late get back
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.