SqlServerCeException "There was an error parsing the query" help ....
-
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 = , ]
-
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 = , ]
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
-
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
-
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 ?
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
-
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
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 ?
-
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 ?
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.
-
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.
-
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 ?
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