How To Update XML Element With LINQ

Mar 15, 2010

I'm editing XML element with the following XML:
<?xml version="1.0" encoding="utf-8"?>
<!--Test XML with LINQ to XML-->
<LabSerivceInfo><LabService>
<ServiceType>Copy</ServiceType>
<Price>1</Price></LabService>
[Code] .....
How to update the ServiceType and Price where ServiceType = varServiceType?

View 2 Replies


ADVERTISEMENT

Update XML Element With LINQ To XML?

Mar 15, 2010

I'm trying to update an element in the XML document below:

Here's the code:

Dim xmldoc As XDocument = XDocument.Load(theXMLSource1)
Dim ql As XElement = (From ls In xmldoc.Elements("LabService") _
Where CType(ls.Element("ServiceType"), String).Equals("Scan") _

[code]....

But, I got this error message:

Object reference not set to an instance of an object.Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Error line:ql.SetValue("23")

View 1 Replies

Using LINQ To Return Element In Collection, Would Like To Return Nothing If Element Not Found?

Mar 3, 2011

I would like the following function to return Nothing if the element with the specified key is not in the collection. Instead, it returns an error - something to the effect of "no element found"

Public Class MyCollection
Inherits System.Collections.ObjectModel.Collection(Of MyType)
Public Function FindByActivityKey(ByVal searchValue As Integer) As MyType

[code]....

View 1 Replies

Linq To Xml Get Certain Element Value?

Apr 14, 2011

The XML sample below has two records and each record has three similar Nodes (<datafield tag="500" >) What I want to accomplish is get the value of the second Node <datafield tag = "5000">. The fallowing code I gets the value for all three nodes but I want something like get elementat(1). I tried this but it didn't worked MsgBox(xEle.Elements.ElementAt(1).Value)

Code:

Dim xd As XDocument = XDocument.Load("C:UsersstopeteDesktopMarc_convertxml.xml")
If xd IsNot Nothing Then
Dim datafields = From datafield In xd.Descendants("datafield")

[code]....

View 2 Replies

Add An Element To The XML Document With LINQ To XML?

Mar 15, 2010

I'm adding an element to existing XML doc with the following code:

Dim theXMLSource As String = Server.MapPath("~/Demo/") & "LabDemo.xml"
Dim nodeElement As XElement
Dim attrAndValue As XElement = _

[code]....

It makes error like this:

System.NullReferenceException: Object reference not set to an instance of an object.Object reference not set to an instance of an object.Error line: nodeElement.Add(New XElement(attrAndValue))

View 4 Replies

Get The Value Of An XML Element Using Linq Even When Empty?

May 13, 2010

Please excuse my stupidity, I tend to find the traversing XML overly complicated.

[Code]...

Once it gets to staffBio I get an error saying "Object reference not set to an instance of an object." obviously because that node does not exist. My question is how can I assign the value to a variable even when it is empty without having to do a conditional check before each assignment?

View 2 Replies

Increment Element Using LINQ To XML?

Nov 12, 2009

Using VB.NET (3.5), i have an ArrayList of Employees. I'm trying to build an XML representation (to feed another system) and one of the fields is a simple incrementing ID, starting at 1.[code]...

View 1 Replies

Linq To XML: Writing Xsi Into An Element?

Feb 25, 2011

Just playing about with LinqToXml and I need to form a xelement as follows:

Dim xe As XElement = _
<Xml>
<ElementOne>
<SubElement></SubElement>
<SubElement></SubElement>

[Code]...

This creates an error here: xsi:type "XML namespace prefix 'xsi' is not defined"

Is it possible to write this in Linq to xml?

View 1 Replies

LINQ XML Get Parent Element

Oct 28, 2010

Using the XML elements below, I am trying to locate all table elements where they have a column@Name equal to a specific item such as "email" and return the Database@Location and Table@Name. My LINQ statement returns the proper table@name but for each element found returns the first database@Location for both. So my question is, how can I search for a column@Name and return the proper Database@Location and Table@Name [Code]

View 1 Replies

LINQ To XML Syntax For XML Element With Attributes?

May 13, 2009

I'm a bit of a LINQ newbie and I was having some trouble with the following. I'm trying to perform a query using LINQ on an XML file and store the results in a list of DataClass objects that match the XML.I've got an XML file that is defined like this:

<NewDataSet>
<NewDataTable>
<Field>Accepted ASNs</Field>
<Val>59</Val>[code]....

I have created a Data class to support this XML format. What I would like to do is create a LINQ Query to grab these 3 records and store them into a List of my DataClass. In order to support multiple Order elements, I have my class defined with a generic list of "Order" structs... It looks like this:

Public Class ASNData
Private _field As String
Private _value As String[code].....

how to grab the 3 order elements and store them into my list of Order structs.

View 4 Replies

Linq To Xml Output Valaue From A Certain Element?

Apr 15, 2011

It has two records and each record has three similar Nodes (<datafield tag="500">). What I want to accomplish is get the value of the second Node <datafield tag = "5000">. The following code I gets the value for all three nodes but I want something like get elementat(1).I tried this but it didn't worked.

MsgBox(xEle.Elements.ElementAt(1).Value)
Dim xd As XDocument = XDocument.Load("C:UsersstopeteDesktopMarc_conv ertxml.xml")
If xd IsNot Nothing Then
Dim datafields = From datafield In xd.Descendants("datafield")
Where (datafield.Attribute("tag").Value = "500")

[Code]...

View 2 Replies

Linq To XML Remove Element Where Value Is Null?

Apr 19, 2011

I have a XML xElement like[code]...

In order to get rid of Trick nodes where value is null, I wrote:

myXmlElement.<Play>.<Trick>.Where(Function(m) m.<Trick>.Value = "").Remove()

View 4 Replies

.Net LINQ Query To Determine Whether More Than One Element Has The Same Value For A Property?

Jun 28, 2011

I am trying to write a LINQ query which will return true if there are multiple objects which have a property with the same value.

Here is what I have come up with so far:

Formatters.Where(Function(f As DataModel.Formatter) _
Formatters.Select(Function(f2 As DataModel.Formatter) f2.Name.ToLower()).Contains(f.Name.ToLower())).Count > 1

However the above always returns true as long as their are more then 1 elements in the list?

View 1 Replies

C# - Linq - Find Element In Nested Collections

Feb 19, 2011

I have a generic list - SupportedTypeGroups. Each SupportedTypeGroup has SupportedTypes property (generic list of SupportedType). How to construct a Linq query to locate SupportedType with required name?

View 3 Replies

LINQ - Order By Anonymous Type (Value Element)

Jan 5, 2012

I am using linq to fill a gridview with the information from an xml from code behind. I would like to order my Grid according to one of my elements in the xml ("value element").

gvResourceEditor.DataSource = (From resElem In resourceElements.Elements("data") _
Select New With { _
.Key = resElem.Attribute("name").Value, _
.Value = HttpUtility.HtmlEncode(resElem.Element("value").Value), _
.Comment = If(resElem.Element("comment") IsNot Nothing, HttpUtility.HtmlEncode(resElem.Element("comment").Value), String.Empty) _
}).OrderBy(?????)

View 1 Replies

Reading XML Element & Child Nodes Using LINQ

Aug 26, 2009

I am new in LINQ world.I need an urgent help in reading the xml elements using LINQ with specific where condition.I need to find the max air_temp for a county i.e where county name = "Boone" and hour id = "06/03/2009 09:00CDT".[code]

View 3 Replies

Using LINQ To XML With Global Namespace - Xmlns Is Added To Each Non-data Element?

Jan 14, 2010

I have to create an xml doc for a vendor who specifically states they must have their xml as follows:

<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<WMWROOT xmlns="http://www.blahblah.com/BLAH/Interface">
<WMWDATA>[code].......

I cannot find a way to get LINQ to spit out xml the way they want. Question is, can LINQ do it or do I need to resort to hardcoding the xml the old way before LINQ to XML?

View 5 Replies

.net - LINQ Update Method Doesn't Update The Db?

Nov 5, 2010

Public Sub UpdateStaff(ByVal sr As StaffRecord)
Dim oldSr As StaffRecord
Dim q = From staff In db.StaffRecords Where staff.Employee_Number = sr.Employee_Number Select staff
oldSr = q.First
oldSr.Address_Line1 = sr.Address_Line1

[Code]...

The helper function I have written seems to do everything I want apart from update the db. Stepping through the code, the oldSr is updated by the new sr parameter but no update on submit changes.

View 2 Replies

Linq To XML Update Value?

Nov 17, 2010

I'm playing around with Linq and XML and came across a need to update an XML node. Below is my code to read the xml, my question is, can I edit the xml source that I have loaded in to memory (from file) and save it?[cod]e...

View 1 Replies

Update Xml Value Via Linq?

Dec 17, 2010

Im trying to update the "value" Attribute of some xml file that have this structure:

<app-settings>
<setting name="codeBasePath" value="E:data" />
<setting name="server" value="LOCALHOST" />

[Code].....

View 6 Replies

How To LINQ Datatable Update

Sep 21, 2010

discovered the compact mode of this instructions vs usual code. I found sample code for selecting, etc. from a datatable, transforming a column in a list or array - all operations are "Select"s - readonly.I need to make an simple update on a certain rows (using LINQ) from a DISCONNECTED datatable for which now I'm using this

for each dr as datarow in dtable.Rows
dr("MyField") = 77
next

[code].....

View 16 Replies

How To Update Data Using LINQ To SQL

Aug 1, 2011

I need to update a datatable using LINQToSql. Option Strict is ON. Datatable name is Customer with fields customerID, customerName, SalesID. I need to update rows with SalesID = -1.

View 1 Replies

Update List With Linq Instead Of For Each?

Mar 9, 2012

I am a bit new to linq, I am only using linq for filtering the data. [code]...

Con.Numbers is a dictionary, but now I converted it into a list, hence the above code wont work with list[code]....

View 2 Replies

Use Linq To XML To Update A Document?

Aug 31, 2009

In general I have a xml document that i need to update.The query looks like this:

Of course it gives me a "This attribute is readonly" error.[code]...

View 4 Replies

.net - Linq-to-SQL Database Update Fails?

Aug 18, 2010

Very simple update. It simply fails, no error, no change gets made to the database.Dim db As New BarClassesDataContext Dim foo = (From a In db.articles Where a.id = 14 Select a).Single Response.Write("<h3>" & foo.title & "</h3>") foo.title = "This is my new, updated title for article ID #14"
db.SubmitChanges()

Here is the relevent portion of my article class. Also, this is a web form so I have no console. Is there another way to view the T-SQL output?

<Table(Name:="dbo.article")> _
Partial Public Class article
Private _id As Integer
Private _issueid As Integer
Private _dateadded As Date

[Code]...

View 3 Replies

Asp.net - Update Linq To Sql With Variable Names?

Apr 15, 2012

im pretty much a beginner to using ASP.net and linq to sql but what im trying to do is update a column of a table based on a variable. at the momment i have

Dim db As New sqldcDataContext Dim update As tableName = (From i in db.tableNames _ Select i)

i think this selects everything, how could i have two variables, one to store what table to update and the other what column. is this possible?edit: sorry for being unclear im trying to make this as dynamic as possible so i dont have to type in the exact table/col names. something like this but in the linq to sql syntax.

mysql_query("SELECT * FROM ". $table ." WHERE `" . $column . "` = "" . $data ."");

View 2 Replies

LINQ To SQL Update Not Working Correctly

May 11, 2009

I use the following statement to position which row to update;
Dim salonToUpdate = (From r In db.Salons _
Where r.StoreID = storeID _
Select r).Single()
If fileDate = #1/1/1900# OrElse fileDate = Nothing Then
SalonToUpdate.LastDownLoadDate = TableDate
[Code] .....

I've double checked to make sure none of the dates are invalid or null, but when the bolded statement executes, the following sql runs through the trace:
exec sp_executesql N'UPDATE [dbo].[Salons]
SET [LastDownLoadDate] = @p0
WHERE 0 = 1',N'@p0 datetime',@p0='2008-01-04 00:00:00:000'
Of course it's going to fail if LINQ is passing in where 0=1 every time. Shouldn't it be using some unique row identifier, (in my case, the salon id), to update the specific row?

View 2 Replies

Linq Update A Signle Field?

Jun 19, 2009

I am using database compact and i loaded it on my form and i want to update a single field but I cannot, why:

what am doing is:
dim newrec as datatable=(studentdataset."TableName")
dim querie= from det in newrec.asnumerable() _

[code].....

View 5 Replies

Update A Column In A Database Using Linq?

Aug 22, 2009

I use this command to retrieve information from an Access database:

Try
Dim result = From row In Me.ChitaDataSet1.chita.AsEnumerable() _
Where row.Field(Of String)("askID") = x _
Select row[code]....

how to Update a cell in specified row-coloumn coordinates?

View 9 Replies

Web Services - .net Linq Update Data?

Jul 31, 2011

Im using linq and im able get get data ouf of it realy easy. but i seem to not be able to update the data. the program does not error on it and it looks likes it has updated but it does not save te changes.

Public Function UpdateAlarmsbyKey(ByVal objKey As Integer, ByVal IdNumber As String) As Boolean

[Code]...

View 1 Replies







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