.net - Update 2 Table Values In One Query In LINQ?

Apr 26, 2010

I have 2 tables Table1 with columns [BId,Name,Amount] Table2 with columns [CId,BId, ExpenseType,Expense]. BId Is the foreign key in Table2. The Amount field in Table1 is always higher than Expense in Table2. I need to update the values of Amount (increase or decrease) based on value of Expense and I want to do it in single query in LINQ. Eg If the Expense has to be updated with 200, I would decrease(negate) Amount value with 200. If Expense is reduce to 100 then the Amount is increased by a value of 100.

View 1 Replies


ADVERTISEMENT

Linq To SQL / Query From Table

May 18, 2012

I am starting with Linq to SQL in VB.NET, and trying to figure out how to make a simple query to a database.I want to do it all programaticly.I have made a connection to the database with a connectionstring, and this works fine - I can get a message if the database exists or not.But when I want to query a table, I am missing the part where I connest to the table. I have googled a lot to find an answer for thi, but [code]

View 2 Replies

Using LINQ - Query Out Dbf Table?

Sep 2, 2009

I was able to use it for querying out info from an XML file but now i have to use the DBF file from a folder. where i can find out how to query out DBF table using LINQ. I basically need to get data from a column of a DBF table.

View 2 Replies

LINQ To XML To Query Attributes Values

Oct 25, 2011

I am trying to use Linq to Xml to query attribute values that will be used to populate a combo box. My xml looks like this:

<Records>
<Record id="1">
<LogoPositioning>
<Brand id="26">
<Xpos>100</Xpos>
<Ypos>200</Ypos>
[Code] .....

My issue is with getting the attribute values. I tried this:
For
Each xattr
As
XAttribute
In
attr
cboBrandChoice.Items.Add(test.Value)
Next

However, I keep getting the following error:
{"Unable to cast object of type '<GetAttributes>d__8' to type 'System.Xml.Linq.XAttribute'."}
I'm new to using Linq so this error isn't making a whole lot of sense to me.

View 2 Replies

Linq Query Handling Null Values?

Nov 12, 2011

From r In ReceiptLines
Where
r.RECEIPT.RECEIPTDATE >= _reportStartDate
And r.RECEIPT.RECEIPTDATE <= _reportEndDate

[Code].....

I am fetching all departments and their sales, average, count from the ReceiptLine, Receipt, ReceiptDiscount tables. The problem i am facing is, if i remove where discount > 0, I am getting null exception. But if I include that, then I only get sales that has discount. How would I write query that bring all sales less discount (if it has one).

View 2 Replies

Filter Parent / Child Table In Linq Query Based On Entities In Child Table?

Jul 9, 2010

I have a table (Projects) which is linked to projectVersions on projectID..projectVersions contains several columns on which I'd like to filter a returned project (and associated projectVersions) list. For example there is a "capacity" column and a "country" column. I am doing a filtered list of projects on one page and I'd like to include all projects where any one of the associated projectVersions has a capacity of 750ml and a country of "France" for example.It may be that a particular parameter is not set and so I pass a zero to indicate not to filter on that.I guess this needs some kind of subquery as when I try and do something like this: [code] it doesn't work as the "xxx" bit, being one-to-many, expects me to specify an item to get at the entities within and yet I want to query where ANY of the associated versions match one of the criteria.

View 1 Replies

Update One Entity Based On Results Of Another LINQ-to-Entities Query

Apr 9, 2011

I have the following LINQ-to-Entities query:[code]This will give me all the resident assignments for the current year/term. Then I have this LINQ-to-Entities query:[code]This will give me all the rooms. I want to iterate through the assignments and based on what room is assigned update the occupancy in reset_occupancy. I'm not 100% sure how to accomplish this. Here is my pseudo code of what I want to accomplish:[code]

View 1 Replies

Update One Entity Based On Results Of Another LINQ-to-Entities Query?

Dec 15, 2009

I have the following LINQ-to-Entities query:

' Get all the residency assignments that match the term/year.
Dim assignments = From p In dbContext.Residents _
Where p.semester = term _

[code].....

View 1 Replies

Asp.net - Select Query In LINQ Based On Foreign Table

Mar 2, 2011

I have 2 Tables , OrderDetails and Requests In my LINQ to SQL dbml file. OrderDetailsID is a foreign key in Requests Table.

I want to write the query to get the sum of UnitCost from OrderDetails based on OrderId. And If there is a row in Requests Table for each OrderDetailsID, and the Requests.Last.RequestType="Refund" I want to reduce the total refund amount from the main sum otherwise If there is no row based on OrderDetailsID, add to sum.

Here is the way I implement that. I am looking to prevent using "For each".

iRefund = (From od1 In dc.OrderDetails _
Where od1.OrderID =1 _
Select od1.UnitCost).Sum

[Code]....

View 1 Replies

Multi - Table Join Query In ASP.NET To SQL Server Via LINQ?

Jan 29, 2012

I'm working on an ASP.NET 4.0 site, which I inherited ownership of. It has a number of existing LINQ datasources pointing to individual tables. For example, to the Patient Encounter Summary table in SQL Server. The problem is in displaying the data there. It's a normalized database, so that table contains (for example) the provider ID, rather than the provider name.

It's simple enough to join the Patient Counter Summary to the Providers table (in SQL)... but how does one do that in ASP.NET? I'm not sure of the correct nomenclature, but the 'mid layer' is VB.

[Code]...

View 3 Replies

Select Query In LINQ Based On Foreign Table?

Mar 4, 2009

I have 2 Tables , OrderDetails and Requests In my LINQ to SQL dbml file.OrderDetailsID is a foreign key in Requests Table.I want to write the query to get the sum of UnitCost from OrderDetails based on OrderId.And If there is a row in Requests Table for each rderDetailsID, and the Requests.Last.RequestType="Refund" I want to reduce the total refund amount from the main sum otherwise If there is no row based on OrderDetailsID, add to sum

View 3 Replies

.net - Update Students Table Record Using LINQ To SQL?

Aug 22, 2011

I´m trying to update my Students table record using LINQ to SQL. The problem is when one of the Properties of the object changed and 'PropertyChanging' Event is fired using 'SendPropertyChanging()' method.

student_id is a PK
data types are matched

Here is the full ArgumentException:

GenericArguments[2], 'System.String', on
'System.Data.Linq.Mapping.PropertyAccessor+Accessor`3[T,V,V2]'
violates the constraint of type 'V2'.

[code]....

View 1 Replies

Asp.net - Update / Delete The Table Records In ASPNETDB.MDF In Single Update / Delete Query?

Nov 29, 2010

I want to know how to Update / delete the table records in ASPNETDB.MDF in single update / delete query ?

View 1 Replies

C# - Use Meta Tales Or Table Names To Construct A Dynamic Query In LINQ?

Feb 8, 2011

Is there a way to use Meta Tales or Table names to Construct a dynamic query in LINQ?

foreach (var metaTable in db.Mapping.GetTables())
{
var queryType = metaTable.RowType.Type;

[code]....

Is there a way to do something like this? The attempt above yields the error:Could not find an implementation of the query pattern for source type 'System.Data.Linq.ITable'. 'Select' not found. Consider explicitly specifying the type of the range variable 'q'.

View 2 Replies

Convert A Two-table Exists Query From SQL To Linq Using Dynamic Fields In The Subquery?

Jun 7, 2011

I'm trying to query old Access database tables and compare them with SQL Server tables.They often don't have primary keys, or they have extra fields that had some purpose in the nineties, etc., or the new tables have new fields, etc.I need to find records - based on a set of fields specified at runtime - that are in one table but not another.So, I do this kind of query all the time in SQL, when I'm comparing data in different tables:

dim fields_i_care_about as string = "field1, field2, field3"
'This kind of thing gets set by a caller, can be any number of fields, depends on the
'table
dim s as string= ""

[code]....

It tells me it can't convert a Boolean - Is there any way to do this without Linq expressions? They seem far more complex than what I'm trying to do here, and they take a lot of code, and also I can't seem to find examples of Expressions where we're comparing two fields in a subquery.Is there a simpler way? I know I could do the usual EXISTS query using JOIN or IN - in this case I don't need the query to be super fast or anything. And I don't need to use a DataTable or DataSet - I can put the data in some other kind of object.

View 1 Replies

C# - Asp.net Query With Insertion Of Values In A Table

Dec 26, 2011

suppose we have three tables in the Database:

[Code]....

View 1 Replies

Update Values In A Dictionary With New Fields Obtained From Wmi Query?

Jan 20, 2012

I still can't assign the process the username of the session id that is associated with it.[code]...

View 1 Replies

Parameterized Query For Insert And Update A Table In MsAccess

Jun 26, 2009

I am using following code for Insert records from LIstview to table in MsAccess:

[Code]...

View 4 Replies

Query Table Retrieve Filtered Values?

May 24, 2011

I am trying to Query a table with data from another table and return a filtered result

Dim i As Integer = 0
For Each lrow In dtlist.Rows()
Dim lat As Double = dtlist.Rows(i)("Latitude") 'CDbl(Me.SubjLat_txt.Text)
Dim lon As Double = dtlist.Rows(i)("Longitude") 'CDbl(Me.SubjLon_txt.Text)

[code]....

Obviously doesnt work but the idea is thats the Value i need to put in the Value Column of dtlist In short the project, loops through one table(dtlist) of address's and gets the distances of it from the address's in the second table(dtsold) then gets the higest value from dtsold within a certain distance?

View 2 Replies

Convert A JSON Constructed From Table To A Datatable For An Update Query?

Jan 29, 2011

I would like to send json data from a HTML table to the ASP.NET code-behind and update the data in and SQL Server database. The code and JSON for the TableProductToUpdate() is below.

function UpdateProductTable() {
$.ajax({
type: "POST",

[code].....

View 2 Replies

Update Excel Values That Read From The Data Table In Ms Word?

Mar 3, 2010

I have to do an application using VB.Net .The application must be able to capture values from ms word data table and map them to ms excel sheet. For your information, i have over 6000 files ms word document, each of them contains 4 data tables using the same format .Then i have this code for read from data table 1 in document 1:

Dim
wb As
Excel.Workbook<br/>

[Code].....

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

.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

Asp.net - Complex Linq Query - Add A .Where() Or .Any() Predicate To Reduce Query Complexity (in VB)?

Sep 14, 2010

I have to join two main tables, and I need to filter the results by elements in an ASP.NET web form. These filters are created on the fly so I have to use a lot of where extensions to filter the query. I want to execute the query with as optimized SQL as possible.

I am first doing a simple join between TW_Sites and TW_Investigators. Then there are two sub-tables that are involved. TW_InvestigatorToArea and TW_InvestigatorToDisease. While most of the where clauses are working fine, I have found a performance issue that won't be an issue right now, but will be an issue as the table gets bigger.

The arrays DiseaseCategories and DiseaseAreas would be the results of a CheckBoxList result.

Protected Sub LoadResults()
'Get Dictionary of Filters
Dim FilterDictionary As OrderedDictionary = Session.Item("InvestigatorFilterDictionary")
' Initialize LinqToSql

[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

Xml - Mix Values From Local Data With Values Returned From Database While Using LINQ To SQL?

Oct 27, 2010

I am creating an xml file with LINQ as follows...

Public Sub CreateXml()
Dim db As New MDataContext
Dim Customers = <gallery columns="3" rows="3">

[code]....

Could i mix local values with the ones returned from the LINQ query...Something like the following?

Public Sub CreateXml(ByVal **Col** As String, ByVal **Row** As String)
Dim db As New MDataContext
Dim Customers = <gallery columns="& **Col** &" rows="& **Row** &">

[code]...

View 1 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

Correct SQL Query: Error "Microsoft Jet Database Engine Cannot Find The Input Table Or Query 'IF'?

Aug 27, 2010

The database:
"ID (Primary key)" | "Title"
0 | "title1"

[code].....

OK, before adding values to database, we should check if a row exists with this values :)TO do this, creating a Stored Procedure is a best way to deal with the database fastly.So... The problem now is, at the runtime, Miss OleDB throw this error:Microsoft Jet database engine cannot find the input table or query 'IF

View 2 Replies







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