Avatar of clooak
clooak

asked on 

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

Avatar of undefined
Last Comment
Fernando Soto
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

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

Avatar of clooak
clooak

ASKER

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")
Avatar of clooak
clooak

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo