[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1593
  • Last Modified:

Is there a way I can trim trailing spaces in a linq query

Is there a way I can trim trailing spaces in a linq query?

        query = From row In list
            Where row.Working = inputData

In the above example, row.working = "No " and inputData = "No".
I know the best fix is to not allow data into the db with trailing spaces, but for now, I need to work with the data I have.

I have tried trimend and contains and neither worked.  but maybe I am not using them correctly?  I am kind of a newbie with linq.

thank you for helping me!
0
ToolTimeGang
Asked:
ToolTimeGang
  • 8
  • 3
1 Solution
 
13ShadowCommented:
Is your working field set as char(3) rather than varchar(3)?
0
 
käµfm³d 👽Commented:
Based on the code you show, I would expect:

query = From row In list
        Where row.Working.TrimEnd().ToUpper() = inputData.TrimEnd().ToUpper()

Open in new window

0
 
ToolTimeGangAuthor Commented:
   Private Function queryWorking(ByRef query As IEnumerable(Of ResponseTimeDto), _
                           list As List(Of ResponseTimeDto), _
                           inputData As String) As List(Of ResponseTimeDto)
        query = From row In list
            Where row.Working.TrimEnd().ToUpper() = inputData.TrimEnd().ToUpper()
        Return query.ToList()
    End Function

Open in new window

When I run this code, I get a nullreference exception on inputdata.trimend().toupper(). Object reference not set to an instance of an object.  Troubleshooting tip is to use the "new" keyword to create an object instance.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ToolTimeGangAuthor Commented:
Ok 13shadow and kaufmed.  I think I have a fix for this:
http://stackoverflow.com/questions/4685578/how-can-i-automatically-trim-whitespace-from-my-linq-queries

I used the fix that Exoas suggested.  It works for now until I have a more permanent solution for the data.

Make sense?  I still would like to fix it in the linq query example at the beginning of this post, but I can't get it to work.
0
 
käµfm³d 👽Commented:
When I run this code, I get a nullreference exception
You need to ensure that the strings you are trimming are not null. You might try:

query = From row In list
        Where row.Working.TrimEnd().ToUpper() = IF(inputData Is Nothing, String.Empty, inputData).TrimEnd().ToUpper()

Open in new window

0
 
ToolTimeGangAuthor Commented:
That still doesn't work.  I am going to stick with Exoas suggestion for now.  Thanks for trying to help!
0
 
käµfm³d 👽Commented:
I am going to stick with Exoas suggestion for now.
Huh?
0
 
ToolTimeGangAuthor Commented:
ok
0
 
ToolTimeGangAuthor Commented:
ok
0
 
ToolTimeGangAuthor Commented:
ok
0
 
ToolTimeGangAuthor Commented:
0
 
ToolTimeGangAuthor Commented:
Other suggestions were not working for me.  This one did work.  not the best solution, but it works.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 8
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now