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. Database access [modified]

Database access [modified]

Scheduled Pinned Locked Moved C#
databasehelpquestion
10 Posts 5 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.
  • S Offline
    S Offline
    sreecahitu
    wrote on last edited by
    #1

    Am retrieving data from my databese engine to read the data, but encountering an error at dr.Read(), con.close(). public string constring = @" "; SqlConnection con = new SqlConnection(constring); SqlCommand cmd = new SqlCommand("select * from emp",con); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); con.Close(); "Invalid token '(' in class, struct, or interface member declaration", what could be the reason for this? -- modified at 18:59 Friday 9th February, 2007

    A C 2 Replies Last reply
    0
    • S sreecahitu

      Am retrieving data from my databese engine to read the data, but encountering an error at dr.Read(), con.close(). public string constring = @" "; SqlConnection con = new SqlConnection(constring); SqlCommand cmd = new SqlCommand("select * from emp",con); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); con.Close(); "Invalid token '(' in class, struct, or interface member declaration", what could be the reason for this? -- modified at 18:59 Friday 9th February, 2007

      A Offline
      A Offline
      Aaron VanWieren
      wrote on last edited by
      #2

      This should be posted in the SQL Database section.

      _____________________________________________________________________ Our developers never release code. Rather, it tends to escape, pillaging the countryside all around. The Enlightenment Project (paraphrased comment) Visit Me at GISDevCafe

      1 Reply Last reply
      0
      • S sreecahitu

        Am retrieving data from my databese engine to read the data, but encountering an error at dr.Read(), con.close(). public string constring = @" "; SqlConnection con = new SqlConnection(constring); SqlCommand cmd = new SqlCommand("select * from emp",con); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); con.Close(); "Invalid token '(' in class, struct, or interface member declaration", what could be the reason for this? -- modified at 18:59 Friday 9th February, 2007

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

        sreecahitu wrote:

        new SqlConnection(" ");

        How is that a connection string ?

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        S 1 Reply Last reply
        0
        • C Christian Graus

          sreecahitu wrote:

          new SqlConnection(" ");

          How is that a connection string ?

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          S Offline
          S Offline
          sreecahitu
          wrote on last edited by
          #4

          I indicated the connection string correctly with source,user name and pwd, but i didnt mention here. string constring=@"source, user="",password="" "; SQLConnection con=new SqlConnection("cosnstring");

          C 1 Reply Last reply
          0
          • S sreecahitu

            I indicated the connection string correctly with source,user name and pwd, but i didnt mention here. string constring=@"source, user="",password="" "; SQLConnection con=new SqlConnection("cosnstring");

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

            OK, I think we've found the problem.

            sreecahitu wrote:

            string constring=@"source, user="",password="" ";

            When you use @, you need two " to make *one* quote. So, it's user=""name""

            sreecahitu wrote:

            SQLConnection con=new SqlConnection("cosnstring");

            Because you put it in quotes, you're passing in the value cosnstring, instead of the value of the variable with that name.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

            S 1 Reply Last reply
            0
            • C Christian Graus

              OK, I think we've found the problem.

              sreecahitu wrote:

              string constring=@"source, user="",password="" ";

              When you use @, you need two " to make *one* quote. So, it's user=""name""

              sreecahitu wrote:

              SQLConnection con=new SqlConnection("cosnstring");

              Because you put it in quotes, you're passing in the value cosnstring, instead of the value of the variable with that name.

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

              S Offline
              S Offline
              sreecahitu
              wrote on last edited by
              #6

              If i write as follows, string constring=@"source, user=,password= "; SQLConnection con=new SqlConnection(cosnstring); still am getting an error.

              D C D 3 Replies Last reply
              0
              • S sreecahitu

                If i write as follows, string constring=@"source, user=,password= "; SQLConnection con=new SqlConnection(cosnstring); still am getting an error.

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                This may seem like a stupid question, but which database engine are you using? SQL Server, MySQL, Access, Oracle, ... ? You can find the correct format for your connection string at http://www.connectionstrings.com[^].

                Dave Kreskowiak Microsoft MVP - Visual Basic

                1 Reply Last reply
                0
                • S sreecahitu

                  If i write as follows, string constring=@"source, user=,password= "; SQLConnection con=new SqlConnection(cosnstring); still am getting an error.

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

                  That doesn't look like a valid connection string to me. Did you post the actual code in the first instance ? Or did you change it in other ways ? This does not account for your actual error, really, which makes no sense to me, right now.

                  Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                  S 1 Reply Last reply
                  0
                  • C Christian Graus

                    That doesn't look like a valid connection string to me. Did you post the actual code in the first instance ? Or did you change it in other ways ? This does not account for your actual error, really, which makes no sense to me, right now.

                    Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                    S Offline
                    S Offline
                    sreecahitu
                    wrote on last edited by
                    #9

                    ya, thank you all, i modified wrongly. I got the problem, the problem is with declaring the declaration of string.

                    1 Reply Last reply
                    0
                    • S sreecahitu

                      If i write as follows, string constring=@"source, user=,password= "; SQLConnection con=new SqlConnection(cosnstring); still am getting an error.

                      D Offline
                      D Offline
                      dabuskol
                      wrote on last edited by
                      #10

                      Just remove the @ character

                      Dabsukol

                      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