.net - How To Pass Linq To SQL Types To A Function
Aug 27, 2011
The code below is used in a Linq to SQL solution, and is in the Load event of a form. It works fine to display an ordered list of people's names, and set the value member to that person's ID. However, I'm going to be using these 'people' comboboxes a lot, so I'd like to put a sub into my Utility code there is only one line in the form's Load event.
I want to call something like: Call ComboboBoxPeople(cbo, tblTurnbackMain, ReportedByID)
The sub would begin like: Public Sub ComboboxPeople(cbo as Combobox, tbl as 'sometype', fld as 'someothertype')
What can I use as the parameter types for tbl and fld?
[Code]...
View 1 Replies
ADVERTISEMENT
Jan 24, 2010
I am trying to pass a lambda function to Linq's orderby and cannot get it to work.
The relevant code is:
Dim myordering = Function(m) m.Count
If isAlphaOrder Then
myOrdering = Function(m) m.Key 'Order by Alphabet
[Code].....
View 4 Replies
May 25, 2010
I have a query that can be summarised in SQL as follows;
Select
S.StockCode
From
StockToCheck As S
[Code]....
Where the S var is a list of strings. This gives the error 'S' is not declared and points to the S in the function call / join (GetPOSStock). So it does not seem possible to do this in Linq, can anyone confirm?
View 1 Replies
Oct 12, 2011
I want to make an numerical integration method with takes in an analytic function and integrate it over a specific interval. For the numerical integration procedure I want to use some procedures in nr.com. The problem is that these are programmed in C++ and they uses functors to pass a function to the integration method. How can I do this in VB 2010?
I want to initialize the function (i.e. set a=1,b=0 for function y(x)=a*x+b) and then pass the function to the integration method. Then when the integration method call the function it only calls the function with one parameter (i.e. x since a,b is already set)
What is the best way to do this in VB2010?I want to make a general integration method where I can pass any single valued function and integration limits.
I have just started using VB, and from what I have found so far it seems like the tools you have is
- to us a delegate for the function
- to use a lambda expression for the function
- send a pointer/adressOf
- to create a function class/structure and submit this to the function
As for now I am most inclined to create a function-class. But I am not really sure how.F.ex. I make different classes for each "uniqe function" I want to integrate, but how can I pass them to the integration function when I need to specify the argument type in the integration-function-call?This seems like a basic problem which applies to many Math operations, so I think it would be very useful to clarify this.
View 2 Replies
Mar 23, 2012
I am calling a XML web service (standard web service project based on .NET 3.5) and trying to pass custom types as parameters. The custom types are defined in my consuming code and the web service references an assembly from the consuming code to get access to the types. The serialization is being handled by .NET.
<WebMethod()> _
Public Function MyMethod() As MyType
Dim myValue as new MyType
return myValue
End Function
In my consuming code I created a web reference to the service and the proxy classes were created. I gave the service the namespace "WebService". Next I try to make a call to the service and assign the result from the call to a variable, something like this:
Dim service As New WebService.ServiceNameSoapClient
Dim response As New MyType
response = service.MyMethod()
I get an error from the IDE saying that it cannot convert type mynamespace.WebService.MyType to mynamespace.Entities.MyType. It appears to me that although the types are similar they are being treated as different because of the different namespaces, which makes sense of course.
Edit: So from what I am reading I believe this is by design, that is the proxy types are simply different types and cannot be directly associated with the types in the consuming code.
View 2 Replies
Oct 23, 2011
Today, I'm proceeding with my college work, and am having a little trouble. I'm writing a function, but would like to pass custom types through as parameters, for example Function Game(Section as Game_Section) code here End Function I tried using a structure, but it kept giving me errors
View 13 Replies
Jun 29, 2009
I have a problem using linq and anonymous types in an asp.net vb.net application.When I write the code above, I have 2 errors :
- "declarations of variable with Option Strinct On requires an As clause"
- "the name 'item' is not declared"
Public Sub MyFunc(ByVal xe As System.Xml.Linq.XElement)
Dim lstitems = From it In xe.Elements Select txt = it.@Text, value = it.@Value
For Each item In lstitems
Dim s As String = item.txt
Next
End Sub
Does it mean that is not possible to use Option Strict On and Option Explicit On ?Or I make a syntax error ?Or is it just a bad configuration of my application ?
View 2 Replies
Mar 19, 2010
I would like to use reflection on an anonymous type resulting from a LINQ to SQL query. I know that reflection on anonymous types works in general. The following code successfully generates a propertyinfo array with two elements:
Dim MyObject = New With {.Col1 = 1, .Col2 = "Test"}
Dim t As Type = MyObject.GetType()
Dim pilist As PropertyInfo() = t.GetProperties
[Code].....
View 7 Replies
May 28, 2012
I want to make a GetAllContacts method which takes a sort parameter of type Func(Of Contact, TKey) which is the same type that the OrderBy method for an IEnumerable(Of Contact) takes.[code]"Too many arguments to extension method 'Public Function ElementAtOrDefault(index As Integer) As Contact' defined in 'System.Linq.Enumerable'." on the second parameter.
View 2 Replies
May 4, 2012
I am trying to query for records where that column IS NULL:
Dim UnassignedSubSvc =
From c In CurrentContext.SubService
Where c.Product.ProductSubServiceId **is null**
Select c).ToList()
View 1 Replies
Jul 2, 2011
Supposing the referenced List below contains 2 elements:
Dim Countries = From c In List _
Select New With { .Country = c.Country, .CountryID = c.CountryID }
The code above returns
.Country=Spain .CountryID = 1
.Country=Spain .CountryID = 1
How can I get the distinct values? The Countries query should contain only
.Country=Spain .CountryID = 1
View 5 Replies
Mar 11, 2009
Any best approach to what I'm trying to achieve (linq to sql, returning list of data to show in a grid/list etc etc)... Its complaining about anonymous type conversion, and from what I'm reading, thats not elegant way of doing it.
Public Function GetHistory(ByVal historyId As Integer) As List(Of ?????????)
Using dc As New myDataContext(Application.GetConnection)
Return (From t In dc.ActionTypes, a In t.MyTable Where a.HistoryID = historyId Select a.ActionOn, a.ActionBy, t.Description, a.ImpactedItem, a.ActionDescription).ToList
End Using
End Function
View 4 Replies
Oct 25, 2011
I am in the process of learning LINQ to Objects. I am querying an array of reference elements using LINQ. In the code below, which I have marked with asteriks and PROBLEM, I am having difficulty returning any values for and I suspect its because of the multiple Select arguments.
'Program name:Querying an Array of Invoice Objects
'Created/revised:
'Project description:To demonstrate the use of LINQ to query objects
[Code].....
View 4 Replies
Mar 30, 2012
Im a student doing an assignment, how do i pass the value from a sub procedure to a function procedure....i want to pass the value from decSubtotal to a function procedure named CalculateDiscount; check out my code--
[Code]...
View 1 Replies
Jul 14, 2011
I was toying around with some of the linq samples that come with LINQPad. In the "C# 3.0 in a Nutshell" folder, under Chater 9 - Grouping, there is a sample query called "Grouping by Multiple Keys". It contains the following query:
from n in new[] { "Tom", "Dick", "Harry", "Mary", "Jay" }.AsQueryable()
group n by new
{
[Code].....
View 1 Replies
Apr 24, 2012
I've got the below, where I'm grouping a collection by a propery, then wanting to access the properties of my group. Problem I have is with the anonymous typing. Because of option strict I have to give an explicit type but I can't work out what the type should be. The below doesn't compile because t.HeadAccountKey isn't a value (as t has a type of object). So either I need do some casting or my linq selector is wrong,
[Code]....
View 1 Replies
Apr 24, 2012
The documentation has an example about grouping on multiple properties[code]...
Is it possible to rewrite the original query to just return IEnumerable(Of CustomerRegionGroup), or do I have to use the anonymous type, and run a second query on the result of the first?
View 1 Replies
Jun 29, 2010
I'm trying to translate some C# LINQ code into VB.NET and am stuck on how to declare an anonymous type in VB.NET.[code]How do you translate C#'s new { ... } syntax into VB.NET?
View 2 Replies
May 6, 2009
Say I create two sets of tuples like so:
Dim losSPResults As List(Of spGetDataResults) = m_dcDataClasses.spGetData.ToList
Dim loTupleKeys = From t In losSPResults Select t.key1, t.key2
[CODE].....................
Now I want to perform set operations on these two lists like so:
Dim loTupleSetDifference = loTupleKeys.Except(loTupleExistingKeys)
Obviously, Linq can't perform a comparator on sets if it doesn't know the sets have uniform definitions, so it will give me this build error:
Option Strict On disallows implicit
conversions from
'System.Collections.Generic.IEnumerable(Of
< anonymous type>)' to
'System.Collections.Generic.IEnumerable(Of
< anonymous type>)'.
How do I work with the declaration of these sets to make them mesh?
Still getting the same compile error:
'*** If we have initialized the list of tools, check to make sure it's up to date Dim loTupleDatabaseTools = From tt In lottTorqueTools _Select StationIndex = tt.station_index, SlotNumber = tt.slot_number
[CODE]...............
Error is here:
Dim loTupleSetDifference = loTupleDatabaseTools.Except(loTupleToolObjects)
Error 5Option Strict On disallows
implicit conversions from
[CODE]........................
View 1 Replies
Mar 17, 2010
Every LINQ example I have seen for VB.NET anonymous types claims I can do something like this:
[code]...
Now when I go to iterate through the collection(see example below), I get an error that says "Name "x" is not declared. For Each x in Infos It's like VB.NET doesn't understand that Infos is a collection of anonymous types created by LINQ and wants me to declare "x" as some type. (Wouldn't this defeat the purpose of an anonymous type?) I have added the references to System.Data.Linq and System.Data.DataSetExtensions to my project. Here is what I am importing with the class:
[code]...
View 4 Replies
May 17, 2012
i am downloading data from xml using linq library those data i want to add them on a textblock item
TextBlock1.Text = TextBlock1.Text & result
but it has an error :
Error 1 Operator '&' is not defined for types 'String' and 'System.Xml.Linq.XElement'.
When i am changing this line to :
TextBlock1.Text = TextBlock1.Text & result.Tostring
it works but it adds this data :
"<"data> data <"/data>
instead of :
hello
View 1 Replies
Feb 17, 2012
So you know how PHP internal functions usually return a boolean FALSE when a function fails, or some other data type when the function succeeds? Is this possible in VB .Net?For instance, lets say this simple code here Public Function TrySomething(ByVal Param As String) \what would go here??
[Code]...
You see I want to return a BOOLEAN false when a function fails, and a string when the function works. I've looked everywhere, and when I search for "return multiple types" all i find is Tuple.
View 4 Replies
Nov 19, 2010
I'm having trouble with VB LINQ syntax. I have a web service that is returning JSON to jQuery and I need the index of the items but can't figure it out. [code]...
View 1 Replies
Nov 14, 2009
I am using the following line of LINQ to drill down into an element. Is it possible to expands this code to drill further down so that I can add content to the <population> element in "Test2". I want to be able to do somthing like element.SetValue(1000000). However I need to expand the code below so that I can pass the entire query results into the variable called "element"'
Dim eles = From c In doc.Descendants("File") _
Where c.Attribute("Name").Value = "Test2" _
Select c
[code]....
View 3 Replies
Jan 6, 2011
I`m looking for a way to parse a parameter name like linq does.I want to filter before i download the date from the database.With LINQ the data is already red into a dataset. I only want to select data from the database witch i need. how i can send a property name to a function without using the property name as string and without to use to mutch code inside the function and without creating an instance of the object, etc.
Module
Module1
Dim user
As user =
[code]....
View 13 Replies
Jul 11, 2011
How can I pass stored procedure name dynamically to Linq-to-SQL, vb.net and get the result into a datatable.
View 2 Replies
Feb 6, 2010
I have a LINQ query:[code]How can I pass "MyField" to the Sub and make the LINQ "Where" clause work?
View 2 Replies
Jan 25, 2010
I have the following statement, I want to turn it into a Public Shared Function :
If isEmployee Then
Dim employeeInstance As New Employee
employeeInstance = GetEmployeeInstanceByUserId(userId)
[Code]....
Public Shared Function GetWorkerInstance(Byval isEmployee as Boolean) As ...(not sure what to write here)...
There two possible return Type. I'm not sure what I should declare for the function return type.
View 2 Replies
Nov 9, 2011
I am having problems with my code, where I get the "Object cannot be cast from DBNull to other types" message when Insert(). I get the message on every Insert to this table, even though the data is successfully inserted. If I Update the same data after Insert(), it does so without error. I have checked my values and none of them are DBNull. Even when the same values are passed on Insert that are passed on Update.
My code is :
Private Sub Save()
Dim bo As tbl_GL
bo = New tbl_GL()
bo.ConnectionString = AppConfig.ConnectString
[Code] .....
View 4 Replies
Jun 8, 2012
Lets say I click a button on a form that calls a function in a data access class. This function inserts a record into a table in a database. The function returns an integer value for the record id of the newly inserted record. Now lets say the insert failed (syntax error, timeout, whatever). I can return a zero to the calling routine to indicate the failure, but not the error message. So in general, what's the most appropriate way to handle getting information back to a calling routine when the return parameter data type doesn't allow it?
View 3 Replies