Linq or SQL - Check data from datatable if column data contains a letter "E"

Hey

I am developing a .NET web-app and I am importing a huge amount of data from an excel sheet, to a datatable.

Before I do any changes to the data fetched, I want to make sure that a certain field in the excel, does not contain character "E". If so, stop the import process.

Any idea what this linq query should look like? I have tried numerous of ideas, with no result.

I would rather use an SQL query, but couldnt find a way to query the dataset by using it.
clooakAsked:
Who is Participating?
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.

Fernando SotoRetiredCommented:
Hi clooak;

Something like the following code snippet should work. Make sure to assign the correct table index.

var results = (from row in DataSetInstance.Table[0].AsEnumerable()
               where row.Field<string>("ColumnNameHere").Contains("E") 
               select row).Count();
               
if( results == 0 )
{
    // Do the processing
}
else
{
    // E was found in the column do NOT do processing.
}

Open in new window

0
clooakAuthor Commented:
Splendid perfect! Theres only one problem left which I can't really figure out..

The data i am comparing is looking similar to 124245E2414 notice the E in the middle, I can't  get it to convert the entire value to string, so that I can compare it.

Any idea? I have tried setting soemthing like .ToString() so it looks something like
row.Field<string>("Order_num").ToString().Contains("E")
0
clooakAuthor Commented:
If I changed the
row.Field<double>("Order_num")
to row.Field<string>("Order_num").ToString()

Then It works with the E values, but the rest that doesnt have E is still considered as Double will yield error when trying to read them.

So I gotta figure out a way to force the Double/String I am reading to string. Somehow.
0
Fernando SotoRetiredCommented:
Hi clooak;

The value 124245E2414 falls outside the valid range of negative 1.79769313486232E308 to positive 1.79769313486232E308 for a double. But if the data column of Order_num is actually a double then the following should work.

var results = (from row in DataSetInstance.Table[0].AsEnumerable()
               where row.Field<double>("Order_num").ToString().Contains("E") 
               select row).Count();
               
if( results == 0 )
{
    // Do the processing
}
else
{
    // E was found in the column do NOT do processing.
}

Open in new window

0

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
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
Query Syntax

From novice to tech pro — start learning today.