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 6601513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:45:45+00:00 2026-05-25T18:45:45+00:00

I am writing a program in C# using Visual Studio 2010 and gets an

  • 0

I am writing a program in C# using Visual Studio 2010 and gets an error when retrieving data from a .sdf-file.

Here follow the code of the class retrieving data from the database:

//DataAccess.cs

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlServerCe;
/// <summary>
/// Demonstrates how to work with SqlConnection objects
/// </summary>

    namespace GameDAL
    {
        /// <summary>
        /// Serve as main database layer.
        /// </summary>
        /// 

        public class DataAccess
        {
            SqlCeConnection conn = null;
            SqlDataReader rdr = null;
            // 3. Pass the connection to a command object
            SqlCommand cmd = null;
            string strConnection =null;
            string dbfile =null;
            string TABLE_NAME = "Statistics";
            string conString;
            /// <summary>
            /// Initialise connection and connection string
            /// </summary>
            public DataAccess()
            {
                InitConnection();
            }

            public void InitConnection()
            {
                // Create a connection to the file Statistics.sdf in the program folder
                MessageBox.Show("test new reflection");
                dbfile = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\Statistics.sdf";
                MessageBox.Show("test time new conn");

                conn = new SqlCeConnection("datasource=" + dbfile);
                MessageBox.Show("test before opening");

                conn.Open();
                MessageBox.Show("test before new connectionstr");
                conString = Properties.Settings.Default.StatisticsConnectionString;

                if (conn == null)
                   MessageBox.Show("warning connis null !!!!!");

            }

            /// <summary>
            /// Returns connection to database.
            /// </summary>
            /// <returns></returns>
            public SqlCeConnection GetConnection()
            {
                return conn;
            }

            /// <summary>
            ///                     /// Write one row to database containing winner name ,winner score and, winner nr of cards.
            /// </summary>
            /// <param name="winnerName">Name of winner</param>
            /// <param name="winnerScore">Score of winner</param>
            /// <param name="winnerNrOfCards"></param>
            public void WriteDataToDatabase(string winnerName, int winnerScore, int winnerNrOfCards )
            {

                // Retrieve the connection string from the settings file


                // Open the connection using the connection string.
                using (conn)
                {

                    // Insert into the SqlCe table. ExecuteNonQuery is best for inserts.
                    using (System.Data.SqlServerCe.SqlCeCommand com = new System.Data.SqlServerCe.SqlCeCommand("INSERT INTO"+TABLE_NAME + "VALUES(@winnerName, @winnerScore, @winnerNrOfCards)", conn))
                    {
                        com.Connection = conn;
                        com.Parameters.AddWithValue("@winnerName", winnerName);
                        com.Parameters.AddWithValue("@winnerScore", winnerScore);
                        com.Parameters.AddWithValue("@winnerNumberOfcards", winnerNrOfCards);
                        com.ExecuteNonQuery();
                    }
                }
            }

            /// <summary>
            /// Read data from database.
            /// Put data in array list with DataFromDatabase-instances, containing the stats for each game.
            /// <returns>Returns arrayList with all data of database..</returns>

            public List<DataFromDatabase> ReadAllDataFromDataBase()
            {
                string winnerName;
                int winnerScore;
                int winnerNrOfCards;

                if (conn == null)
                    InitConnection();

                //System.Collections.ArrayList arrayListWithStatsFromDatabase= new System.Collections.ArrayList ();
                List<DataFromDatabase> dataFromDatabaseList = new List<DataFromDatabase> ();
                SqlCeCommand com = new SqlCeCommand("SELECT winnerName, winnerScore, winnerNumberOfCards FROM Statistics");
                MessageBox.Show("Now we inside ReadAllData and will be using conn");

                if (conn == null)
                    MessageBox.Show("warning connis null !!!!! before using CONN");
                else
                    MessageBox.Show("conn is " + conn);
                using (conn)
                {
                    // Read in all values in the table.
                    MessageBox.Show("conn OK.. comm is" + com);

                    //("SELECT * FROM"+ TABLE_NAME, conn);         
                    using (com)
                    {
                        com.Connection = conn;
                        MessageBox.Show("Now we inside ReadAllData and will be using reader..");
                        SqlCeDataReader reader = com.ExecuteReader();
                        MessageBox.Show("Now we inside ReadAllData and..after exec reader reader..");
                        //Add data from each row in table of database.
                        while (reader.Read())
                        {
                            winnerName = reader.GetString(0);
                            winnerScore = reader.GetInt32(1);
                            winnerNrOfCards = reader.GetInt32(2);
                            dataFromDatabaseList.Add(new DataFromDatabase(winnerName, winnerScore, winnerNrOfCards));
                        }

                    } //end of using

                } //end of using 2

                return dataFromDatabaseList;
            } //end of methods

        } //end of class
    } //end of namespace..

//Database table:
Statistics.sdf

Table name: Statistics
Columns: winnerName, winnerScore,winnerNumberOfCards

The bug occurs in this methods:

ReadAllDataFromDatabase() when executing SqlCeDataReader reader = com.ExecuteReader();

Error message: ‘{“There was an error parsing the query. [ Token line number = 1,Token line offset = 58,Token in error = Statistics ]”}’

Error report:

    System.Windows.Markup.XamlParseException was unhandled
      Message=Anropet av konstruktorn av typen BlackJack.MainWindow som matchar de angivna bindningsbegränsningarna utlöste ett undantag. radnummer 4 och radposition 76.
      Source=PresentationFramework
      LineNumber=4
      LinePosition=76
      StackTrace:
           vid System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
           vid System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
           vid System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
           vid System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
           vid System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
           vid System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
           vid System.Windows.Application.DoStartup()
           vid System.Windows.Application.<.ctor>b__1(Object unused)
           vid System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
           vid MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           vid System.Windows.Threading.DispatcherOperation.InvokeImpl()
           vid System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
           vid System.Threading.ExecutionContext.runTryCode(Object userData)
           vid System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
           vid System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
           vid System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
           vid System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           vid System.Windows.Threading.DispatcherOperation.Invoke()
           vid System.Windows.Threading.Dispatcher.ProcessQueue()
           vid System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           vid MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           vid MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
           vid System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
           vid MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           vid System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
           vid MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           vid MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
           vid System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
           vid System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
           vid System.Windows.Application.RunDispatcher(Object ignore)
           vid System.Windows.Application.RunInternal(Window window)
           vid System.Windows.Application.Run(Window window)
           vid System.Windows.Application.Run()
           vid BlackJack.App.Main() i D:\Programmering\C-sharp Malmö Advancd\BlackJack3\BlackJack\BlackJack\obj\x86\Debug\App.g.cs:rad 0
           vid System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           vid System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           vid System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
           vid System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
           vid System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
           vid System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
           vid System.Activator.CreateInstance(ActivationContext activationContext)
           vid Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
           vid System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           vid System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
           vid System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           vid System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.Data.SqlServerCe.SqlCeException
           Message=There was an error parsing the query. [ Token line number = 1,Token line offset = 58,Token in error = Statistics ]
           Source=SQL Server Compact ADO.NET Data Provider
           HResult=-2147217900
           NativeError=25501
           StackTrace:
                vid System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan()
                vid System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
                vid System.Data.SqlServerCe.SqlCeCommand.ExecuteReader(CommandBehavior behavior)
                vid System.Data.SqlServerCe.SqlCeCommand.ExecuteReader()
                vid GameDAL.DataAccess.ReadAllDataFromDataBase() i D:\Programmering\C-sharp Malmö Advancd\BlackJack3\BlackJack\GameDAL\DataAccess.cs:rad 133
                vid BlackJack.GameManager.ReadInDataFromDatabase() i D:\Programmering\C-sharp Malmö Advancd\BlackJack3\BlackJack\BlackJack\GameManager.cs:rad 660
                vid BlackJack.MainWindow.ResetListANDGUIWithStatisticsAndReadInNewDataFromDatabase() i D:\Programmering\C-sharp Malmö Advancd\BlackJack3\BlackJack\BlackJack\MainWindow.xaml.cs:rad 94
                vid BlackJack.MainWindow..ctor() i D:\Programmering\C-sharp Malmö Advancd\BlackJack3\BlackJack\BlackJack\MainWindow.xaml.cs:rad 71
           InnerException: 

What is the reason for this error?

  • 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-05-25T18:45:46+00:00Added an answer on May 25, 2026 at 6:45 pm

    Statistics is a reserved word, escape its name with [] notation as string TABLE_NAME = "[Statistics]".

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

Sidebar

Related Questions

I'm writing an application using Visual Studio C++ 2010 to perform Data Acquisition and
I am writing a program in C for windows using visual studio 2010. I
I am writing a program using Delphi 2006 and storing data in XML files
I am writing an application program using swing. I need to exit from the
Writing a python program, and I came up with this error while using the
My scenario I'm using Visual Studio 2010 with Entity Framework 4.1 I have a
We have been getting a range on infuriating error dialogs using Visual Studio 2008
I just started writing a small application in C++ using Visual Studio C++ 2008
I am writing a simple C++ database, using Visual Studio 2008 express edition, like
I'm using 64 bit Windows 7 Pro and Visual Studio 2010 Pro. I'm trying

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.