Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7714777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:12:59+00:00 2026-06-01T02:12:59+00:00

I am trying to learn about XML literals in VB. In a learning project

  • 0

I am trying to learn about XML literals in VB. In a “learning” project which based on a console application template the following compiles and runs without error (and without any special Imports statements nor references added):

Module Module1
Sub Main()
    Dim db As New AdventureWorksDataContext
    Dim stores = <?xml version="1.0"?>
                 <stores>
                     <%= From vStoreWithDemographics In db.vStoreWithDemographics _
                         Select <store>
                                    <ID>
                                        <%= vStoreWithDemographics.BusinessEntityID %>
                                    </ID>
                                    <Name>
                                        <%= vStoreWithDemographics.Name %>
                                    </Name>
                                    <AnnualSales>
                                        <%= vStoreWithDemographics.AnnualSales %>
                                    </AnnualSales>
                                    <BankName>
                                        <%= vStoreWithDemographics.BankName %>
                                    </BankName>
                                    <SquareFeet>
                                        <%= vStoreWithDemographics.SquareFeet %>
                                    </SquareFeet>
                                    <NumberEmployees>
                                        <%= vStoreWithDemographics.NumberEmployees %>
                                    </NumberEmployees>
                                </store>
                     %>
                 </stores>
    stores.Save("c:\stores.xml")
    Process.Start("c:\stores.xml")
End Sub

End Module

Yet I tried repeating the same in a new project based on a Windows Forms app and I get errors on the last 2 statements (both saying only “Declaration expected“; also note: I compared the References for the console app with those provided by default for the winforms app and added System.Data.Linq then given the error I added 2 Imports statements but I still get the errors).

Imports System.Diagnostics
Imports System.Xml.Linq.XDocument
Public Class Form1
Dim db As New AdventureWorksDataContext
Dim stores = <?xml version="1.0"?>
             <stores>
                 <%= From vStoreWithDemographics In db.vStoreWithDemographics _
                     Select <store>
                                <ID>
                                    <%= vStoreWithDemographics.BusinessEntityID %>
                                </ID>
                                <Name>
                                    <%= vStoreWithDemographics.Name %>
                                </Name>
                                <AnnualSales>
                                    <%= vStoreWithDemographics.AnnualSales %>
                                </AnnualSales>
                                <BankName>
                                    <%= vStoreWithDemographics.BankName %>
                                </BankName>
                                <SquareFeet>
                                    <%= vStoreWithDemographics.SquareFeet %>
                                </SquareFeet>
                                <NumberEmployees>
                                    <%= vStoreWithDemographics.NumberEmployees %>
                                </NumberEmployees>
                            </store>
                 %>
             </stores>
    stores.Save("c:\stores.xml")                   'error here
    Process.Start("c:\stores.xml")                 'error here
End Class

Please tell me what I am missing. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:13:01+00:00Added an answer on June 1, 2026 at 2:13 am

    Your second block of code is not inside of a method. It needs to be inside of a Sub or Function:

     Public Class Form1
          Public Sub SomeFoo()
               Dim db As New AdventureWorksDataContext
               Dim stores = <?xml version="1.0"?>
                               <stores>
                                    <%= From vStoreWithDemographics In db.vStoreWithDemographics _
                                         Select <store>
                                                       <ID>
                                                            <%= vStoreWithDemographics.BusinessEntityID %>
                                                       </ID>
                                                       <Name>
                                                            <%= vStoreWithDemographics.Name %>
                                                       </Name>
                                                       <AnnualSales>
                                                            <%= vStoreWithDemographics.AnnualSales %>
                                                       </AnnualSales>
                                                       <BankName>
                                                            <%= vStoreWithDemographics.BankName %>
                                                       </BankName>
                                                       <SquareFeet>
                                                            <%= vStoreWithDemographics.SquareFeet %>
                                                       </SquareFeet>
                                                       <NumberEmployees>
                                                            <%= vStoreWithDemographics.NumberEmployees %>
                                                       </NumberEmployees>
                                                  </store>
                                    %>
                               </stores>
               stores.Save("c:\stores.xml")
               Process.Start("c:\stores.xml")
          End Sub
     End Class
    

    And then at some point in your application something will call SomeFoo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to learn about the Orchard MVC application. I see the following
I am currently trying to learn about OpenGL ES for the iPhone and following
I am trying to learn about Google maps API. I have a project that
I'm trying to learn about shift-reduce parsing. Suppose we have the following grammar, using
I'm trying to learn about grails with Google App Engine and JPA by following
I'm trying to learn about reverse engineering, using Minesweeper as a sample application. I've
I'm working on a school project, and basically we're trying to learn about stack
I'm trying to learn about $_SESSION variables and I've been following some tutorials I've
Trying to learn about php's arrays today. I have a set of arrays like
I'm trying to learn about catamorphisms and I've read the Wikipedia article and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.