LINQ .Startswith Or .Contains Problems In .NET4?

Aug 3, 2010

In my code I can easily use "where Obj.Feld = String", but using "where Obj.Feld.StartsWith("a")" doesn't work. See the following two functions:

[Code]...

The first function (byFileName) works fine. The second function (LikeFileName) doesn't. Using Startswith I get "Object reference not set to an instance of an object." What am I doing wrong?Database is an array of Objects, a structure consisting of strings

View 4 Replies


ADVERTISEMENT

C# - Convert The NServiceBus PubSub .net4

Jun 22, 2011

Im trying to convert the nServiceBus PubSub .net4 example into vb and I'm struggling at one point which I think is a language issue but I thought I would ask the experts. The code in question is from the publisher:

[Code]...

View 2 Replies

Unable To INSERT INTO Command - ASP.NET4?

Feb 14, 2012

I am having trouble with the insert command, my code is:

Protected Sub btnTestator_Click(sender As Object, e As System.EventArgs) Handles btnTestator.Click
Dim WillsDataSource As SqlDataSource = New SqlDataSource()
WillsDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ToString()

[code]....

aatblWills1 is my sql server table with 3 fields: WillID(PrimaryKey, integer auto increment); UserName(nvarchar(150)) and TestatorName(nvarchar(150)) (there are some other fields in the table but I've set them to allow nulls)I am not getting an error message, it is just not inserting any records into the database.

View 4 Replies

Populate DataGridView With StartsWith?

Jun 10, 2011

I have two DataGridViews in one window. The first one displays 2 columns, itemNo and taskWhen I click on a row in this grid, I want to populate the second grid with corresponding material. It is organized so that the itemNo in grid1 is 1, 2, 3, and so on, and so when a row is clicked, I want grid2 to show data that is 1.0, 1.1, 1.2, 2.0, 2.1 and so on. This data is all available in a table that exists within a dataset. However, tableAdapters do not use the .StartsWith function. I am able to get the information from grid1 when it is clicked on using Me.DataGridView1.CurrentRow.Cells(0).Value.ToString but how can I use this to get the data from the table into grid2

View 1 Replies

VS 2010 StartsWith Not Working?

May 30, 2011

I am trying to check if the string starts with certain words before I even add it to my item list, but it doesn't seem to return true even when it should return true.. File I am reading through with my application:

[Constructor.ReplicationHandler]
MeshNames=(ConvexMeshName="",StaticMeshName="52325332",EmitterClassName"")
MeshNames=(ConvexMeshName="",StaticMeshName="3255232",EmitterClassName"")
MeshNames=(ConvexMeshName="",StaticMeshName="644363",EmitterClassName"")
MeshNames=(ConvexMeshName="",StaticMeshName="4636434621646",EmitterClassName"")
MeshNames=(ConvexMeshName="",StaticMeshName="2626352",EmitterClassName"")

[Code]...

View 13 Replies

Use Select And Case Statements Along With Startswith?

Jul 10, 2009

i have a situation in which i have to check if the string starts with something and then perform something....First i used "If" as below

If utn.text.startswith("Fuel") then
messagebox.show("Fuel Purchase is selected")
End If

[code]....

Now i have to use Select and Case statements along with startswith...?

View 4 Replies

Working On StartsWith And EndsWith Methods

Feb 13, 2011

I am working on my application as I am checking ip using with .StartsWith and .EndsWith method. If the ip is equals then it will equals with US. However I have got an error with end of statement expected error using with this line: [code] I have tried to use "And" instead of "&", but I still get the same error.

View 4 Replies

Asp.net - Cannot Create A Process In A COM Object (written In .Net4) From An Asp (vbscript) Site?

Jan 14, 2011

I'm updating an old process that already exists, which works as follows:The user submits a form which runs the following asp (simplified, names changed):

[Code]...

View 1 Replies

WCF Server Application Unavailable - Run Application Written In .NET4.0 (IIS6+)?

Oct 27, 2010

I am trying to run simple application (e.g. generated from template by VS.NET 2010) on IIS6. I changed it to run with .NET 4.0 (its application pool) and checked with regiis (this pool has 4.0). I also changed all possible httpHandlers (svc etc), to run with NET4.0. All possible rights are checked (i think so). Almost every request results in "Server Application Unavailable" (sometimes it is empty page with -2146232576 (0x80131700) value) and "...Please review this log entry to discover what caused this error to occur." but EventViewer and IIS Log are empty.

View 2 Replies

C# - Create An Expression Tree To Do The Same As "StartsWith"?

Dec 29, 2010

Currently, I have this method to compare two numbers

Private Function ETForGreaterThan(ByVal query As IQueryable(Of T), ByVal propertyValue As Object, ByVal propertyInfo As PropertyInfo) As IQueryable(Of T)
Dim e As ParameterExpression = Expression.Parameter(GetType(T), "e")

[code]....

It works fine and is consumed in this way

query = ETForGreaterThan(query, Value, propertyInfo)

As you can see, I give it an IQueryable collection and it add a where clause to it, base on a property and a value. Y can construct Lessthan, LessOrEqualThan etc equivalents as System.Linq.Expressions.Expression has this operators predefined.How can I transform this code to do the same with strings? System.Linq.Expressions.Expression don't give me a predefined operator like "contains" or "startwith"?

View 2 Replies

.net - ActiveRecord Linq/NHibernate Linq Not Building Query Completely?

Jul 14, 2011

given this function:

Public Function Search(ByVal StartIndex As Integer, _
ByVal MaxResults As Integer, _
ByVal AccountNumber As String, _
ByVal LastName As String, _

[Code]....

instead of what I expected:

Select count(*) from remitline where lastname = "smith"

What am I doing wrong building up the where clause? I'm using Castle ActiveRecord 2.1

View 1 Replies

Performance Gain In LINQ Query Vs LINQ Stored Procedure?

Aug 6, 2009

if there is that much of a performance gain in running a LINQ stored procedure versus a LINQ query?

View 1 Replies

Linq To Entities. GetPropety(name).GetValue Not Recognised By Linq?

Apr 20, 2011

I have a listbox on my xaml form that I bound to a List(Of MyType) property. I populated this list like so:

Dim fields As List(Of CheckableFields) = New List(Of CheckableFields)
Using context As ITIPEntities = New ITIPEntities()
Try[code]....

Now I'm at the point where the user selects the fields they want included in a report and I need to iterate over the required fields. This is my linq query:

For Each checkedField In _requiredFields
If checkedField.IsChecked Then
If checkedField.FieldData IsNot Nothing AndAlso checkedField.FieldData.Trim IsNot String.Empty Then[code].....

View 1 Replies

How To Get Lamda In LINQ To Actually Filter For Dynamic Linq

Sep 10, 2009

Example-I have a person class

Public Class Person
Private _fname As String
Public Property Fname() As String

[Code]...

View 2 Replies

LINQ Query Using The Dynamic LINQ Library?

Mar 31, 2011

Forgive my ignorance on this.I have this LINQ Query:Dim ngBikersDataContext As New CarBikeWalkDataContext

bikersList = (From c In ngBikersDataContext.Reg_Bikers _
Order By c.L_Name _
Select New Bikers() With { _
.BikerID = c.BikerID, _
.F_Name = c.F_Name, _

[Code]...

with the error "Overload resolution failed because no accesible 'Select' accepts this number of arguments."
Over the "NEW" I get an error " ')'expected."

View 1 Replies

"System.ArgumentException: An Item With The Same Key Has Already Been Added." When Trying To Order An In-memory LINQ Query By A LINQ Association?

Jan 27, 2011

We are doing a query against an in-memory collection of LINQ data objects. The wrinkle is that we are ordering by a column in a related table whose records have not necessarily been loaded yet (deferred loading:)

Dim oPkgProducts = _
From b In oBillPkg.BillProducts _
Where b.Successful.GetValueOrDefault(Common.X_INDETERMINATE) = _

[code]....

View 1 Replies

.net - Linq Expressions With Linq To Entities?

Feb 28, 2012

The pattern I'm trying to avoid is checking if a string (normally a control's text value) is null/empty, and if it is, comparing it using Contains to a field in my data. Obviously the field isn't hard-coded into my extension, neither is the object type.What I've got works perfectly in Linq to Objects, but I get the generic run-time error "LINQ to Entities does not recognize the method 'System.String Invoke(GenericQueryHelper.Customer)' method, and this method cannot be translated into a store expression." when using an entity framework model.

Here's what I have:

<System.Runtime.CompilerServices.Extension()>
Public Function CompareAndFilter(Of T)(source As System.Linq.IQueryable(Of T), expressionField As System.Linq.Expressions.Expression(Of System.Func(Of T, String)), compareTo As String)

[code]....

I want my usage to look something like this:

Dim results = repository.Customers.CompareAndFilter(Function(c) c.FirstName, searchText)

I do need to get this running against a SQL database really, as it is filtering results, so I don't want to be doing that in memory.

View 2 Replies

C# - Convert Code LINQ To SQL In C # LINQ To SQL In .net?

Jun 27, 2012

How can I convert this code LINQ to SQL in C # LINQ to SQL in Vb.net

[Code]...

View 2 Replies

LINQ To SQL - Add In Row_Number To A LINQ To SQL Query?

Aug 31, 2011

How do I add ROW_NUMBER to a LINQ query or Entity? How can I convert this solution to VB.NET?

[Code]...

I'm having trouble porting that last line. I have been unable to locate a VB.NET example. I'm actually not looking for any paging functionality like the example provides, just good old-fashioned Row_Number(Order By X) row index.

View 1 Replies

Convert An Object System.Data.Linq.DataQuery To System.Linq.IQueryable?

Oct 21, 2009

How can I convert an object of type System.Data.Linq.DataQuery to System.Linq.IQueryable?I'm working with Visual Basic/Silverlight, and the source code of my query is as follows:

Public Function Get_Cli_Pag() As IQueryable(Of V_Cliente_Pagare)
Dim Qry = From P In Me.Context.Pagares Join C In Me.Context.Codigos On C.Codigo

[code]....

View 1 Replies

VS 2010 Upgrade From 2008 To 2010 - Now LINQ - IntelliSense Is Not Working For LINQ Stuff

Apr 20, 2010

I just upgraded a project from VB 2008 to VB 2010. Before, the project did not use LINQ. I have started implementing it. So, I have updated the target framework from 2.0 to 3.5, and added a reference to System.Core, and imported the namespace System.LINQ to the entire project and also imported System.Data.LINQ into the form I'm working with (because it was not available in the list for Imported Namespaces in the references tab).

It's not throwing any errors now, but my IntelliSense is not working for LINQ stuff.

For example... I write this:

[CODE]....................

Then, if I type S. on the next line, the IntelliSense doesn't grab what it should for S (Only get Equals, GetHashCode, GetType, ReferenceEquals, and ToString, instead of the options I should get like Count, First, FirstOrDefault, etc...). If I Type S.First. then its the same thing, no IntelliSense that lists the available fields for S, just the standard options (Equals, GetHashCode, GetType, ReferenceEquals, and ToString). I should be seeing my column names in my table when I type S.FirstOrDefault.

So any ideas what is going on? When I type the code, for example, MessageBox.Show(S.FirstOrDefault.FirstName), it works perfectly. But it doesn't change the casing of the text (so it would read s.firstordefault.firstname) and no intellisense while doing it. But no errors. BTW - Everything works perfectly when creating a NEW VS 2010 application, it's just my projects upgraded from Visual Basic 2008 that have this issue.

View 2 Replies

LINQ Query Is Enumerated - Turn On Some Kind Of Flag That Alerts Me Each Time A LINQ Query Is Enumerated?

Sep 22, 2009

I know that LINQ queries are deferred and only executed when the query is enumerated, but I'm having trouble figuring out exactly when that happens.Certainly in a For Each loop, the query would be enumerated.What's the rule of thumb to follow? I don't want to accidentally enumerate over my query twice if it's a huge result.

For example, does System.Linq.Enumerable.First enumerate over the whole query? I ask for performance reasons. I want to pass a LINQ result set to an ASP.NET MVC view, and I also want to pass the First element separately. Enumerating over the results twice would be painful.It would be great to turn on some kind of flag that alerts me each time a LINQ query is enumerated. That way I could catch scenarios when I accidentally enumerate twice.

View 3 Replies

Converting Linq To C# Linq?

Feb 22, 2012

I recently switched from VB to C# and have, for the most part, been able to make the transition without too much trouble. Currently I am working on converting a VB.Net program into C# and am having trouble with a couple of code blocks that include Linq.

This is one of the VB.Net lines of code that I am having trouble with:

I have tried to do the same thing in C# like this:

I am getting a compile error on the dt, which says Could not find an implementation of the query pattern for source type 'System.Data.DataTable'.'GroupBy' not found. VS also has issues with the whole into Emailers = group;

I have tried to get this right using examples from my search but have not been able to get it right.

View 2 Replies

Linq .Where With An OR Instead Of An AND?

Jul 28, 2009

suppose I wanted to make a function that returned a list of people based on 2 criteria ... FirstName = 'Ed' Or LastName = 'Smith'.The key here being the OR. If I do something like the following:

dim qry = From p in db.Person select p.FirstName, p.LastName
qry = qry.Where(Function(p) p.FirstName = 'Ed')
qry = qry.Where(Function(p) p.LastName = 'Smith')

[code].....

View 7 Replies

VB Linq To C# Linq?

Oct 19, 2011

convert it to C# equivalent

Dim dtData As DataTable = Session("Data")
Dim aFilters = From oRow In dtData _
Where oRow(i_oColumn.BaseColumnName) IsNot DBNull.Value _

[Code].....

View 1 Replies

Way To Use Linq

Jul 6, 2011

My friend told me some linq and mysql.

I not know what is LINQ.

is dll?

is addins for visual studio?

where do i download?

View 2 Replies

XML To SQL Using Linq?

Sep 22, 2010

I am having some difficulties with sending XML data to SQL using Linq.I have been following the tutorial link below, however my XML data doesn't contain a root value like <order number> to go through each of the XML data. There is no unique reference as part of the <quote> information.[URL]..

Is there a way I can submit the changes to SQL using the <reference> field as the unique field even though it is not related to <quote>?

[Code]...

View 9 Replies

.net - Converting VB Linq To C#?

Apr 12, 2011

I'm in the process of teaching myself C# by converting an existing project and am stuck converting the following vb linq code:

Dim outStuff = From tt In (From t In Products.SelectMany(Function(p) If(p.tags IsNot Nothing, p.tags, New ObservableCollection(Of TagModel)))
Group By tagName = t.name,
v = (Aggregate p In Products Where If(p.tags IsNot Nothing, p.tags.Contains(t), Nothing) Into Sum(p.views)),
nl = (Aggregate p In Products Where If(p.tags IsNot Nothing, p.tags.Contains(t), Nothing) Into Sum(p.num_likes))

[Code]...

var x = Products.SelectMany(p => (p.tags != null) ? p.tags : new ObservableCollection<TagModel>());
var tags = from t in x group t by t.name into g select new { tagname=g.First().name};

View 2 Replies

.net - Grouping Using LINQ?

Feb 5, 2010

I'm having a heck of a time with transforming a simple SQL Query into a LINQ query(using vb btw)

Here is my SQL:
SELECT USRDEFND5
FROM int_gp_employee
GROUP BY USRDEFND5

[Code]...

I've tried a number of different variations of the LINQ. My current statement is:

From b In xmlFile...<row> Group b...<usrdefnd5> By b...<usrdefnd5> INTO group when I foreach through the resulting collection, EVERY line (17000) shows up.

View 2 Replies

.net - InvalidCastExeption In LINQ To XML?

May 17, 2011

I am using LINQ to XML to take some data from resources , and here I have a function, where I take some values and then I create a new object (Type Translation), so when I call the function I get a Translation object. By now I have this code:

Public Shared Function RetrieveTranslation(ByVal file As String) As List(Of clsTranslation)
Dim valuetrans = From vl In XElement.Load(file).Elements("data") Select (New clsTranslation With {.Filename = file, .Value = vl.Element("value").Value, .TranslationId = vl.Attribute("name").Value})
Return valuetrans
End Function

The problem is that with this code I got this error:

Unable to cast object of type 'WhereSelectEnumerableIterator2[System.Xml.Linq.XElement,clsTranslation]' to type 'System.Collections.Generic.List1[clsTranslation]'.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved