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. C# - Get DataTable from Access. Please, help me. I can not know this bugs.

C# - Get DataTable from Access. Please, help me. I can not know this bugs.

Scheduled Pinned Locked Moved C#
helpcsharp
17 Posts 4 Posters 2 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.
  • C Christian Graus

    OK, so v stands for string ? Well, that's horrid, but whatever. If you want help, you'll have to give us your SQL, because that's where the error is, that's what the error message says. It seems to me unlikely that you've been coding for long if you don't understand that, so you have time to revisit your coding standard, which is kind of messy. You don't need to put a letter before methods, ever, and even variables, it just makes them hard to read.

    Christian Graus Driven to the arms of OSX by Vista.

    D Offline
    D Offline
    dan sh
    wrote on last edited by
    #6

    Christian Graus wrote:

    You don't need to put a letter before methods, ever, and even variables

    How about just keeping first letter of its datatype? Something like this:

    string sConn;

    Loading signature. Please wait...

    C 1 Reply Last reply
    0
    • D dan sh

      Christian Graus wrote:

      You don't need to put a letter before methods, ever, and even variables

      How about just keeping first letter of its datatype? Something like this:

      string sConn;

      Loading signature. Please wait...

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #7

      Well, that's hungarian notation and it makes more sense, I guess, but it's very much out of vogue nowadays. The IDE will tell you the data type easy enough. The P in front of method names was more bizarre. I note he's still not actually given us the info we need to fix his bug.

      Christian Graus Driven to the arms of OSX by Vista.

      P 1 Reply Last reply
      0
      • C Christian Graus

        OK, so v stands for string ? Well, that's horrid, but whatever. If you want help, you'll have to give us your SQL, because that's where the error is, that's what the error message says. It seems to me unlikely that you've been coding for long if you don't understand that, so you have time to revisit your coding standard, which is kind of messy. You don't need to put a letter before methods, ever, and even variables, it just makes them hard to read.

        Christian Graus Driven to the arms of OSX by Vista.

        T Offline
        T Offline
        thuyphuongid
        wrote on last edited by
        #8

        v: express variable of method l: local in method. vStrSQL = "select * from User where user = 'aaa' and passwd = 'bb'; I tested vStrSQL on MS Access. It is true. It used folow: vStrSQL = "select * from User where User = '" + txtUser.Text + "' and Passwd = '" + txtPassword.Text + "'"; DataTable lTbl = mUti.PGetDataTable(mConnectString, mStrSQL, "tbl"); //// Error ... System.Data.OleDb.OleDbException: Syntax error in FROM clause. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)

        C T 2 Replies Last reply
        0
        • T thuyphuongid

          v: express variable of method l: local in method. vStrSQL = "select * from User where user = 'aaa' and passwd = 'bb'; I tested vStrSQL on MS Access. It is true. It used folow: vStrSQL = "select * from User where User = '" + txtUser.Text + "' and Passwd = '" + txtPassword.Text + "'"; DataTable lTbl = mUti.PGetDataTable(mConnectString, mStrSQL, "tbl"); //// Error ... System.Data.OleDb.OleDbException: Syntax error in FROM clause. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #9

          thuyphuongid wrote:

          v: express variable of method l: local in method.

          Can I suggest you do this with casing instead ? In any case, why does it matter, if a variable was passed in, unless it's a class ? You realise that your code means I can erase your database during the login process if I feel like it ? Research SQL Injection attacks. Could it be that you're calling a method that requires only a single result, but you're doing a select * ? What if you do a select Top 1 * ? Or could it be because your table name and a column name are the same ? The SQL itself looks fine, you are right there.

          Christian Graus Driven to the arms of OSX by Vista.

          T P 2 Replies Last reply
          0
          • T thuyphuongid

            v: express variable of method l: local in method. vStrSQL = "select * from User where user = 'aaa' and passwd = 'bb'; I tested vStrSQL on MS Access. It is true. It used folow: vStrSQL = "select * from User where User = '" + txtUser.Text + "' and Passwd = '" + txtPassword.Text + "'"; DataTable lTbl = mUti.PGetDataTable(mConnectString, mStrSQL, "tbl"); //// Error ... System.Data.OleDb.OleDbException: Syntax error in FROM clause. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)

            T Offline
            T Offline
            thuyphuongid
            wrote on last edited by
            #10

            Sorry! It is not contain mUti. It correct: DataTable lTbl = PGetDataTable(mConnectString, mStrSQL, "tbl");

            C 1 Reply Last reply
            0
            • T thuyphuongid

              Sorry! It is not contain mUti. It correct: DataTable lTbl = PGetDataTable(mConnectString, mStrSQL, "tbl");

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #11

              Why do your methods start with a P ?

              Christian Graus Driven to the arms of OSX by Vista.

              P D 2 Replies Last reply
              0
              • C Christian Graus

                Well, that's hungarian notation and it makes more sense, I guess, but it's very much out of vogue nowadays. The IDE will tell you the data type easy enough. The P in front of method names was more bizarre. I note he's still not actually given us the info we need to fix his bug.

                Christian Graus Driven to the arms of OSX by Vista.

                P Offline
                P Offline
                Paul Conrad
                wrote on last edited by
                #12

                Christian Graus wrote:

                that's hungarian notation

                Not really used anymore.

                Christian Graus wrote:

                P in front of method names was more bizarre

                That got me scratching my head. Wondering what the hell that was.

                "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                1 Reply Last reply
                0
                • C Christian Graus

                  thuyphuongid wrote:

                  v: express variable of method l: local in method.

                  Can I suggest you do this with casing instead ? In any case, why does it matter, if a variable was passed in, unless it's a class ? You realise that your code means I can erase your database during the login process if I feel like it ? Research SQL Injection attacks. Could it be that you're calling a method that requires only a single result, but you're doing a select * ? What if you do a select Top 1 * ? Or could it be because your table name and a column name are the same ? The SQL itself looks fine, you are right there.

                  Christian Graus Driven to the arms of OSX by Vista.

                  T Offline
                  T Offline
                  thuyphuongid
                  wrote on last edited by
                  #13

                  Ok. Thank you for your help. See u later.

                  P 1 Reply Last reply
                  0
                  • C Christian Graus

                    Why do your methods start with a P ?

                    Christian Graus Driven to the arms of OSX by Vista.

                    P Offline
                    P Offline
                    Paul Conrad
                    wrote on last edited by
                    #14

                    Got me on that one :laugh:

                    "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                    1 Reply Last reply
                    0
                    • C Christian Graus

                      thuyphuongid wrote:

                      v: express variable of method l: local in method.

                      Can I suggest you do this with casing instead ? In any case, why does it matter, if a variable was passed in, unless it's a class ? You realise that your code means I can erase your database during the login process if I feel like it ? Research SQL Injection attacks. Could it be that you're calling a method that requires only a single result, but you're doing a select * ? What if you do a select Top 1 * ? Or could it be because your table name and a column name are the same ? The SQL itself looks fine, you are right there.

                      Christian Graus Driven to the arms of OSX by Vista.

                      P Offline
                      P Offline
                      Paul Conrad
                      wrote on last edited by
                      #15

                      Christian Graus wrote:

                      Research SQL Injection attacks

                      I noticed that with the wonderful string concatenation going on there.

                      "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                      1 Reply Last reply
                      0
                      • T thuyphuongid

                        Ok. Thank you for your help. See u later.

                        P Offline
                        P Offline
                        Paul Conrad
                        wrote on last edited by
                        #16

                        In your code, as Christian has said, you are open to sql injection attacks with the string concatenation. Read this fine article preventing sql injection attacks[^]. It is a very good reading and worth bookmarking.

                        "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                        1 Reply Last reply
                        0
                        • C Christian Graus

                          Why do your methods start with a P ?

                          Christian Graus Driven to the arms of OSX by Vista.

                          D Offline
                          D Offline
                          dan sh
                          wrote on last edited by
                          #17

                          May be, P = procedure. But wait do we have procedures in C#. Atleast I am not aware.

                          Loading signature. Please wait...

                          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