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. Web Development
  3. ASP.NET
  4. Placeholder

Placeholder

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestion
6 Posts 2 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.
  • C Offline
    C Offline
    comp_j
    wrote on last edited by
    #1

    Hello Im must read records from Gridview and then insert them to database. Here is the code that I wrote. for (int i = 0; i<counter; i++) { string ID = GridView.Rows[i].Cells[0].Text; objDataAdapter.SelectCommand.CommandText = "INSERT INTO MYTable " + "(Name) VALUES(@Name)"; objDataAdapter.SelectCommand.Parameters.AddWithValue("@Name",Name); } There is an exception: The variable name '@Name' has already been declared. Variable names must be unique within a query batch or stored procedure. Please help me how can I handle this exception.

    C 1 Reply Last reply
    0
    • C comp_j

      Hello Im must read records from Gridview and then insert them to database. Here is the code that I wrote. for (int i = 0; i<counter; i++) { string ID = GridView.Rows[i].Cells[0].Text; objDataAdapter.SelectCommand.CommandText = "INSERT INTO MYTable " + "(Name) VALUES(@Name)"; objDataAdapter.SelectCommand.Parameters.AddWithValue("@Name",Name); } There is an exception: The variable name '@Name' has already been declared. Variable names must be unique within a query batch or stored procedure. Please help me how can I handle this exception.

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

      Does this happen the first time through, or the second ? Why would you make the 'select command' do an insert ? Why not just run the SQL directly without using a data adapter ?

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      C 1 Reply Last reply
      0
      • C Christian Graus

        Does this happen the first time through, or the second ? Why would you make the 'select command' do an insert ? Why not just run the SQL directly without using a data adapter ?

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        C Offline
        C Offline
        comp_j
        wrote on last edited by
        #3

        The problem solved with this: ;) objDataAdapter1.SelectCommand.Parameters.Clear();

        C 1 Reply Last reply
        0
        • C comp_j

          The problem solved with this: ;) objDataAdapter1.SelectCommand.Parameters.Clear();

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

          OK, that's what I suspected, because it's a member object, you're setting the parameter over and over, that's why I asked if it happens the first time. I think those data adapter things are retarded, I never use them.

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          C 1 Reply Last reply
          0
          • C Christian Graus

            OK, that's what I suspected, because it's a member object, you're setting the parameter over and over, that's why I asked if it happens the first time. I think those data adapter things are retarded, I never use them.

            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

            C Offline
            C Offline
            comp_j
            wrote on last edited by
            #5

            Christian Graus wrote:

            I think those data adapter things are retarded, I never use them.

            What do you use instead of adapter?

            C 1 Reply Last reply
            0
            • C comp_j

              Christian Graus wrote:

              I think those data adapter things are retarded, I never use them.

              What do you use instead of adapter?

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

              I write a proper data layer, in a seperate dll, I NEVER put SQL in the presentation layer, and I'd fire anyone who worked for me who did.

              Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

              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