Click here to Skip to main content
15,883,739 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everybody,
Does anybody there can help me with tha traslation of the next code C# to VB.NET? I'm working in WPF Application (VB.NET).
NOTE: I have a problem with the part: ' // Create the query

var rowsFromFile = from c in XDocument.Load(
                           "MyData.xml").Elements lang="sql">"Data").Elements("Rows").Elements("Row")
                                  select c;



I can't found the traslation.

XML
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace ListViewTest
{
    public class MyData
    {
        /// <summary>
        /// Saves items to MyData.xml file in bin folder.
        /// </summary>
        /// <param name="items"></param>
        public void Save(System.Windows.Data.CollectionView items)
        {
            XDocument xdoc = new XDocument();

            XElement xeRoot = new XElement("Data");
            XElement xeSubRoot = new XElement("Rows");

            foreach (var item in items)
            {
                ListViewData lvc = (ListViewData)item;

                XElement xRow = new XElement("Row");
                xRow.Add(new XElement("col1", lvc.Col1));
                xRow.Add(new XElement("col2", lvc.Col2));

                xeSubRoot.Add(xRow);
            }
            xeRoot.Add(xeSubRoot);
            xdoc.Add(xeRoot);

            xdoc.Save("MyData.xml");
        }

        /// <summary>
        /// Gets data from MyData.xml as rows.
        /// </summary>
        /// <returns></returns>
        public IEnumerable<object> GetRows()
        {
            List<ListViewData> rows = new List<ListViewData>();

            if (File.Exists("MyData.xml"))
            {
                // Create the query
                var rowsFromFile = from c in XDocument.Load(
                            "MyData.xml").Elements(
                            "Data").Elements("Rows").Elements("Row")
                                   select c;

                // Execute the query
                foreach (var row in rowsFromFile)
                {
                    rows.Add(new ListViewData(row.Element("col1").Value,
                            row.Element("col2").Value));
                }
            }
            return rows;
        }
    }
}


Thanks
Posted
Updated 8-Oct-13 19:48pm
v2
Comments
[no name] 16-Jul-13 15:39pm    
"// Create the query" is the problem or the nonexistent var keyword is the problem?
alonetmr 16-Jul-13 16:19pm    
Hi,
Yes, i have a problem with "var", apparently it doesn't exist. Why?
[no name] 16-Jul-13 21:35pm    
Why? Because the designers of the VB.NET language did not include it. If you want to know specifically why they did not include it, you would need to go ask Microsoft.
alonetmr 16-Jul-13 16:22pm    
When i do the convertion to VB.NET, i have an error with var. I take this example of:
http://www.codeproject.com/Articles/128878/Sample-Code-to-Add-Edit-and-Delete-Rows-in-a-NET-W
[no name] 16-Jul-13 21:35pm    
So change "var" to a data type type that VB.NET supports.

1 solution

Instead asking others to do your job for you (how else can one understand your request), you should learn the ways to do such translations automatically.



Good luck,
—SA
 
Share this answer
 
Comments
The-vister 26-Sep-13 2:43am    
I know that there are online converters and i know vb syntax and c# syntax and i can convert without any converter but in this code i am using lightswitch and i am new with it, and in the code there are xaml code it is the first time that is see xaml code in vb class. and here is my proble how to convert this xaml to use it in c#???? and thx for your help
Sergey Alexandrovich Kryukov 26-Sep-13 2:59am    
XAML is the same, it does not depend on C# or VB.NET.
—SA
Suvendu Shekhar Giri 1-Dec-15 22:04pm    
5Ed !
Sergey Alexandrovich Kryukov 1-Dec-15 22:47pm    
Thank you, Suvendu Shekhar.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900