Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. SqlServerCeException "There was an error parsing the query" help ....

SqlServerCeException "There was an error parsing the query" help ....

Scheduled Pinned Locked Moved C#
helpdatabasejson
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hande54
    wrote on last edited by
    #1

    SqlCeConnection SqlCeConn = new SqlCeConnection(Information.ConnectionString); SqlCeCommand SqlCeComm = new SqlCeCommand("SELECT * FROM SystemUsers ", SqlCeConn); try { if (SqlCeConn.State == ConnectionState.Closed) SqlCeConn.Open(); SqlCeDataReader SqlRd = SqlCeComm.ExecuteReader(); if (SqlRd.Read()==true){} when I run this code I get the error below. I could not find the reason behind it. I found that IF the query is wrong this type of error could occur but my query is totally works fine. There was an error parsing the query. [ Token line number = 1,Token line offset = 8,Token in error = , ]

    M 1 Reply Last reply
    0
    • H hande54

      SqlCeConnection SqlCeConn = new SqlCeConnection(Information.ConnectionString); SqlCeCommand SqlCeComm = new SqlCeCommand("SELECT * FROM SystemUsers ", SqlCeConn); try { if (SqlCeConn.State == ConnectionState.Closed) SqlCeConn.Open(); SqlCeDataReader SqlRd = SqlCeComm.ExecuteReader(); if (SqlRd.Read()==true){} when I run this code I get the error below. I could not find the reason behind it. I found that IF the query is wrong this type of error could occur but my query is totally works fine. There was an error parsing the query. [ Token line number = 1,Token line offset = 8,Token in error = , ]

      M Offline
      M Offline
      Md Marufuzzaman
      wrote on last edited by
      #2

      try the following... <code>         public string ExecuteScalar(string strConnectionSring, string strScript)             {                   SqlConnection ObjSqlConnection = null;                   SqlCommand ObjSqlCommand = null;                   ObjSqlConnection = new SqlConnection(strConnectionSring);                   string strMessage = null;                   try                   {                         ObjSqlCommand = new SqlCommand(strScript, ObjSqlConnection);                         ObjSqlConnection.Open();                         ObjSqlCommand.ExecuteScalar();                         strMessage = "Succes";                   }                   catch (Exception ex)                   {                         strMessage = ex.Message.ToString();                   }                   finally                   {                         ObjSqlConnection.Close();                         ObjSqlCommand = null;                         ObjSqlConnection = null;                         strScrip

      H 1 Reply Last reply
      0
      • M Md Marufuzzaman

        try the following... <code>         public string ExecuteScalar(string strConnectionSring, string strScript)             {                   SqlConnection ObjSqlConnection = null;                   SqlCommand ObjSqlCommand = null;                   ObjSqlConnection = new SqlConnection(strConnectionSring);                   string strMessage = null;                   try                   {                         ObjSqlCommand = new SqlCommand(strScript, ObjSqlConnection);                         ObjSqlConnection.Open();                         ObjSqlCommand.ExecuteScalar();                         strMessage = "Succes";                   }                   catch (Exception ex)                   {                         strMessage = ex.Message.ToString();                   }                   finally                   {                         ObjSqlConnection.Close();                         ObjSqlCommand = null;                         ObjSqlConnection = null;                         strScrip

        H Offline
        H Offline
        hande54
        wrote on last edited by
        #3

        Thanks for your help. You saved my life :). I have tried it and it has worked fine. Moreover could you explain how I can fetch the query result ?

        M 1 Reply Last reply
        0
        • H hande54

          Thanks for your help. You saved my life :). I have tried it and it has worked fine. Moreover could you explain how I can fetch the query result ?

          M Offline
          M Offline
          Md Marufuzzaman
          wrote on last edited by
          #4

          You are most welcome...:) Well.... You just need to use dataset to fetch query results.... :thumbsup:

          I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.


          Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. Thanks Md. Marufuzzaman

          H 1 Reply Last reply
          0
          • M Md Marufuzzaman

            You are most welcome...:) Well.... You just need to use dataset to fetch query results.... :thumbsup:

            I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.


            Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. Thanks Md. Marufuzzaman

            H Offline
            H Offline
            hande54
            wrote on last edited by
            #5

            I have no idea about dataset :( could yo explain it ? however I tried SqlCeDataReader SqlRd= ObjSqlCeCommand.ExecuteReader(); instead of ObjSqlCeCommand.ExecuteScalar(); and to check if result row number > 0 I used "if (SqlRd.Read() == true)" conditional check. Unfortunately It does not works for query string "SELECT Username, Name, Surname FROM SystemUsers where Username =' " + input + "' and Password = '" +passwd +"'"; there must be one row as a result but It does not return any thing. do you have any idea ?

            A M 2 Replies Last reply
            0
            • H hande54

              I have no idea about dataset :( could yo explain it ? however I tried SqlCeDataReader SqlRd= ObjSqlCeCommand.ExecuteReader(); instead of ObjSqlCeCommand.ExecuteScalar(); and to check if result row number > 0 I used "if (SqlRd.Read() == true)" conditional check. Unfortunately It does not works for query string "SELECT Username, Name, Surname FROM SystemUsers where Username =' " + input + "' and Password = '" +passwd +"'"; there must be one row as a result but It does not return any thing. do you have any idea ?

              A Offline
              A Offline
              Abhishek Sur
              wrote on last edited by
              #6

              use this :

              SqlCeDataReader reader;
              using (reader = ObjSqlCeCommand.ExecuteReader())
              {
              while(reader.Read())
              {
              // Read using reader(0) reader(1) ...
              }
              }

              :) :)

              Abhishek Sur


              My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

              **Don't forget to click "Good Answer" if you like to.

              H 1 Reply Last reply
              0
              • A Abhishek Sur

                use this :

                SqlCeDataReader reader;
                using (reader = ObjSqlCeCommand.ExecuteReader())
                {
                while(reader.Read())
                {
                // Read using reader(0) reader(1) ...
                }
                }

                :) :)

                Abhishek Sur


                My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                **Don't forget to click "Good Answer" if you like to.

                H Offline
                H Offline
                hande54
                wrote on last edited by
                #7

                thank you very much :)

                1 Reply Last reply
                0
                • H hande54

                  I have no idea about dataset :( could yo explain it ? however I tried SqlCeDataReader SqlRd= ObjSqlCeCommand.ExecuteReader(); instead of ObjSqlCeCommand.ExecuteScalar(); and to check if result row number > 0 I used "if (SqlRd.Read() == true)" conditional check. Unfortunately It does not works for query string "SELECT Username, Name, Surname FROM SystemUsers where Username =' " + input + "' and Password = '" +passwd +"'"; there must be one row as a result but It does not return any thing. do you have any idea ?

                  M Offline
                  M Offline
                  Md Marufuzzaman
                  wrote on last edited by
                  #8

                  SqlCommand..::.ExecuteScalar Method: Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored. SqlCommand.ExecuteReader Method: Sends the CommandText to the Connection and builds a SqlDataReader. Dataset: http://msdn.microsoft.com/en-us/library/system.data.dataset.aspx

                  I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.


                  Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. Thanks Md. Marufuzzaman

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups