SQL querying problem
-
Hi! I'm trying to check my database if an entry on a field is already exists in the DB. My Sql command is this:
string Sqlcommand = "SELECT Name FROM Students WHERE Id LIKE '" + TextBox1 + "'";
and I'm executing this as followsSqlCeCommand com = new SqlCeCommand(Sqlcommand, conn);
SqlCeDataAdapter da = new SqlCeDataAdapter(com);after these, just to be sure, I want to check if the query returned some rows or not what should I do? note: I've tried these ->
DataSet s = new DataSet();
da.Fill(s);
if( s == null)
if( s.Tables.Count == 0)
if( da == null)can anybody help? :/
-
Hi! I'm trying to check my database if an entry on a field is already exists in the DB. My Sql command is this:
string Sqlcommand = "SELECT Name FROM Students WHERE Id LIKE '" + TextBox1 + "'";
and I'm executing this as followsSqlCeCommand com = new SqlCeCommand(Sqlcommand, conn);
SqlCeDataAdapter da = new SqlCeDataAdapter(com);after these, just to be sure, I want to check if the query returned some rows or not what should I do? note: I've tried these ->
DataSet s = new DataSet();
da.Fill(s);
if( s == null)
if( s.Tables.Count == 0)
if( da == null)can anybody help? :/
-
Just check the dataset. In this case, your dataset is s. if(s.Tables.Count > 0 && s.Tables[0].Rows.Count > 0) { //... }
Oh THANK YOU! but now it started to give an error
da.Fill(s)
says SqlCeException was unhandled There was an error parsing the query. [ Token line number = 1, Token line offset = 61, Token in error =)] I don't know why, this line did not give an error just 5 minutes ago, I erased new codes and still it gives an error what should I do? :/ -
Oh THANK YOU! but now it started to give an error
da.Fill(s)
says SqlCeException was unhandled There was an error parsing the query. [ Token line number = 1, Token line offset = 61, Token in error =)] I don't know why, this line did not give an error just 5 minutes ago, I erased new codes and still it gives an error what should I do? :/ -
Hmm.. I don't know. Please read this : http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/b5e42031-f90c-4a56-864a-d52f3763131b[^] Probably bug in SQL Server CE
well it seems like a bug, but this is a very simple action to encounter a bug, maybe I should ask in a seperate topic thank you for your answers :D
-
Hmm.. I don't know. Please read this : http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/b5e42031-f90c-4a56-864a-d52f3763131b[^] Probably bug in SQL Server CE
I found that I just made a stupid syntax error in my SQL command :D thank you, my problem is solved :D oh the code project, you're a saint
-
Hi! I'm trying to check my database if an entry on a field is already exists in the DB. My Sql command is this:
string Sqlcommand = "SELECT Name FROM Students WHERE Id LIKE '" + TextBox1 + "'";
and I'm executing this as followsSqlCeCommand com = new SqlCeCommand(Sqlcommand, conn);
SqlCeDataAdapter da = new SqlCeDataAdapter(com);after these, just to be sure, I want to check if the query returned some rows or not what should I do? note: I've tried these ->
DataSet s = new DataSet();
da.Fill(s);
if( s == null)
if( s.Tables.Count == 0)
if( da == null)can anybody help? :/
You should probably also read this: SQL Injection Attacks and Some Tips on How to Prevent Them[^] Nick
---------------------------------- Be excellent to each other :)
-
Hi! I'm trying to check my database if an entry on a field is already exists in the DB. My Sql command is this:
string Sqlcommand = "SELECT Name FROM Students WHERE Id LIKE '" + TextBox1 + "'";
and I'm executing this as followsSqlCeCommand com = new SqlCeCommand(Sqlcommand, conn);
SqlCeDataAdapter da = new SqlCeDataAdapter(com);after these, just to be sure, I want to check if the query returned some rows or not what should I do? note: I've tried these ->
DataSet s = new DataSet();
da.Fill(s);
if( s == null)
if( s.Tables.Count == 0)
if( da == null)can anybody help? :/
-
Hi! I'm trying to check my database if an entry on a field is already exists in the DB. My Sql command is this:
string Sqlcommand = "SELECT Name FROM Students WHERE Id LIKE '" + TextBox1 + "'";
and I'm executing this as followsSqlCeCommand com = new SqlCeCommand(Sqlcommand, conn);
SqlCeDataAdapter da = new SqlCeDataAdapter(com);after these, just to be sure, I want to check if the query returned some rows or not what should I do? note: I've tried these ->
DataSet s = new DataSet();
da.Fill(s);
if( s == null)
if( s.Tables.Count == 0)
if( da == null)can anybody help? :/
Thank y'all :D
-
Hi! I'm trying to check my database if an entry on a field is already exists in the DB. My Sql command is this:
string Sqlcommand = "SELECT Name FROM Students WHERE Id LIKE '" + TextBox1 + "'";
and I'm executing this as followsSqlCeCommand com = new SqlCeCommand(Sqlcommand, conn);
SqlCeDataAdapter da = new SqlCeDataAdapter(com);after these, just to be sure, I want to check if the query returned some rows or not what should I do? note: I've tried these ->
DataSet s = new DataSet();
da.Fill(s);
if( s == null)
if( s.Tables.Count == 0)
if( da == null)can anybody help? :/
Try the following...... Function: <PRE> string strSqlQuery= "SELECT Name FROM Students WHERE Id LIKE '" + TextBox1 + "%'"; object retValue; try { ObjSqlCommand = new SqlCommand(strSqlQuery, ObjSqlConnection); ObjSqlConnection.Open(); retValue = ObjSqlCommand.ExecuteScalar(); } catch (Exception ex) { return (object)ex.Message.ToString(); } finally { ObjSqlConnection.Close(); ObjSqlCommand = null; ObjSqlConnection= null; strSqlQuery = null; } return retValue; </PRE>
Thanks Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
-
Oh THANK YOU! but now it started to give an error
da.Fill(s)
says SqlCeException was unhandled There was an error parsing the query. [ Token line number = 1, Token line offset = 61, Token in error =)] I don't know why, this line did not give an error just 5 minutes ago, I erased new codes and still it gives an error what should I do? :/Hi { using (SqlCeConnection ceConn = new SqlCeConnection("Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)) + "\\Northwind.sdf; Persist Security Info=False")) { ceConn.Open(); SqlCeException was unhandled There was an error parsing the query. [ Token line number = 1, Token line offset = 61, Token in error =)] I don't know why, this line did not give an error just 5 minutes ago, I erased new codes and still it gives an error what should I do? sravanthi veerisetti