First of all thanks Greg for you help so far!!!!!!
I found a solution to copy a row.
var id = eventObj.Source.selectSingleNode("@Id");
var vk = eventObj.Source.selectSingleNode("@VK");
nNewLocalCacheRow = nSampleProductNode.cloneNode(true);
nNewLocalCacheRow.selectSingleNode( "@ArtikelID" ).text = parseInt(id.text);
nNewLocalCacheRow.selectSingleNode( "@VK" ).text = vk.text;
XDocument.DOM.selectSingleNode( "/dfs:myFields/dfs:dataFields/d:Produkte" ).appendChild( nNewLocalCacheRow );
nSampleProductNode ist defined in OnLoad like this:
nSampleProductNode = XDocument.DOM.selectSingleNode( "//d:Umsatz" );
This works fine!
After I figured that out I noticed a new problem:
After choosing some products I would like to update the stock of the chosen products in my sales table. So I wrote this code:
I wrote a custom sql command so that a querry returns the chosen products. To avoid that after this querry my sales table is empty I copy the rows back after executing the querry.
var selectedUms = XDocument.DOM.selectNodes("//d:Umsatz");
var i=0;
var sql = "SELECT * FROM Produkte WHERE Id= ";
var sqlWhere;
while (oSrc = selectedUms.nextNode()){
var artikelID = oSrc.selectSingleNode("@ArtikelID").text;
if (i == 0){
sqlWhere = artikelID + " ";
sql = sql + sqlWhere;
}
else {
sqlWhere = "OR Id =" + artikelID + " ";
sql = sql + sqlWhere;
}
i++;
}
selectedUms = XDocument.DOM.selectNodes("//d:Umsatz");
XDocument.QueryAdapter.Command = sql;
XDocument.Query();
var UmsTab = XDocument.DOM.selectNodes("//d:Umsatz");
UmsTab.removeAll();
while (oSrc = selectedUms.nextNode()){
nNewLocalCacheRow = nSampleProductNode.cloneNode(true);
nNewLocalCacheRow.selectSingleNode("@ArtikelID").text = parseInt(oSrc.selectSingleNode("@ArtikelID").text);
nNewLocalCacheRow.selectSingleNode("@VK").text = oSrc.selectSingleNode("@VK").text;
nNewLocalCacheRow.selectSingleNode("@Nachbestellen").text = oSrc.selectSingleNode("@Nachbestellen").text;
XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:Produkte").appendChild(nNewLocalCacheRow);
}
I looks like it works fine. But when I am trying to save the data back to my database I receive an error like:
"structure of group "dataFields" has changed and is not similar to the structure of the data source"
I can't see any probelm because I use a similar code to querry the data source without any error. After executing this code there is no problem to save data to my database:
var selectedUms = XDocument.DOM.selectNodes("//d:Umsatz");
XDocument.Query();
var UmsTab = XDocument.DOM.selectNodes("//d:Umsatz");
UmsTab.removeAll();
while (oSrc = selectedUms.nextNode()){
nNewLocalCacheRow = nSampleProductNode.cloneNode(true);
if ((oSrc.selectSingleNode("@ArtikelID").text) != ""){
nNewLocalCacheRow.selectSingleNode("@ArtikelID").text = oSrc.selectSingleNode("@ArtikelID").text;
nNewLocalCacheRow.selectSingleNode("@VK").text = oSrc.selectSingleNode("@VK").text; nNewLocalCacheRow.selectSingleNode("@Nachbestellen").text = oSrc.selectSingleNode("@Nachbestellen").text;
XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:Produkte").appendChild(nNewLocalCacheRow);
}
}
}
Christoph