Avatar of clooak
clooak asked on

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


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.
Microsoft SQL ServerC#LINQ QuerySQL

Avatar of undefined
Last Comment
Fernando Soto

8/22/2022 - Mon
Fernando Soto

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
    // E was found in the column do NOT do processing.

Open in new window


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

If I changed the
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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Fernando Soto

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question