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. SQL querying problem

SQL querying problem

Scheduled Pinned Locked Moved C#
databasehelpcomquestion
11 Posts 6 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.
  • E Emmet_Brown

    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 follows

    SqlCeCommand 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? :/

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #2

    Just check the dataset. In this case, your dataset is s. if(s.Tables.Count > 0 && s.Tables[0].Rows.Count > 0) { //... }

    E 1 Reply Last reply
    0
    • L Lost User

      Just check the dataset. In this case, your dataset is s. if(s.Tables.Count > 0 && s.Tables[0].Rows.Count > 0) { //... }

      E Offline
      E Offline
      Emmet_Brown
      wrote on last edited by
      #3

      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? :/

      L S 2 Replies Last reply
      0
      • E Emmet_Brown

        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? :/

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #4

        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

        E 2 Replies Last reply
        0
        • L Lost User

          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

          E Offline
          E Offline
          Emmet_Brown
          wrote on last edited by
          #5

          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

          1 Reply Last reply
          0
          • L Lost User

            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

            E Offline
            E Offline
            Emmet_Brown
            wrote on last edited by
            #6

            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

            1 Reply Last reply
            0
            • E Emmet_Brown

              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 follows

              SqlCeCommand 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? :/

              N Offline
              N Offline
              Nicholas Butler
              wrote on last edited by
              #7

              You should probably also read this: SQL Injection Attacks and Some Tips on How to Prevent Them[^] Nick

              ---------------------------------- Be excellent to each other :)

              1 Reply Last reply
              0
              • E Emmet_Brown

                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 follows

                SqlCeCommand 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? :/

                C Offline
                C Offline
                Calla
                wrote on last edited by
                #8

                Maybe you're screwing up the SQL if you add '" + TextBox1 + "' instead of '" + TextBox1.Text + "'

                1 Reply Last reply
                0
                • E Emmet_Brown

                  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 follows

                  SqlCeCommand 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? :/

                  E Offline
                  E Offline
                  Emmet_Brown
                  wrote on last edited by
                  #9

                  Thank y'all :D

                  1 Reply Last reply
                  0
                  • E Emmet_Brown

                    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 follows

                    SqlCeCommand 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? :/

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

                    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.

                    1 Reply Last reply
                    0
                    • E Emmet_Brown

                      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? :/

                      S Offline
                      S Offline
                      sravsk
                      wrote on last edited by
                      #11

                      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

                      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