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. Problems with primary key

Problems with primary key

Scheduled Pinned Locked Moved C#
databasequestionsql-serversysadminhelp
4 Posts 3 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.
  • M Offline
    M Offline
    mrclash888
    wrote on last edited by
    #1

    I am using a dataset on a table with an already defined primary key in an sql server 2000: SqlCommand currentControllerCommand = new SqlCommand(currentControllerSQL,IDGSConnection); SqlDataAdapter currentControllerAdapter = new SqlDataAdapter(currentControllerCommand); DataSet currentControllerDS = new DataSet(); currentControllerAdapter.Fill(currentControllerDS,collector["TargetUsersTable"].ToString()); When later I try to update the table with the changes on the dataset: SqlCommandBuilder cb = new SqlCommandBuilder(currentControllerAdapter); currentControllerAdapter = cb.DataAdapter; currentControllerAdapter.Update(currentControllerDS,collector["TargetUsersTable"]); It tells me the following: Error submitting changes to the Collector Database. Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information. Why does it tell me that if I have already the primary key defined in the primary table? Thanks for your thoughts! mrclash

    B J 2 Replies Last reply
    0
    • M mrclash888

      I am using a dataset on a table with an already defined primary key in an sql server 2000: SqlCommand currentControllerCommand = new SqlCommand(currentControllerSQL,IDGSConnection); SqlDataAdapter currentControllerAdapter = new SqlDataAdapter(currentControllerCommand); DataSet currentControllerDS = new DataSet(); currentControllerAdapter.Fill(currentControllerDS,collector["TargetUsersTable"].ToString()); When later I try to update the table with the changes on the dataset: SqlCommandBuilder cb = new SqlCommandBuilder(currentControllerAdapter); currentControllerAdapter = cb.DataAdapter; currentControllerAdapter.Update(currentControllerDS,collector["TargetUsersTable"]); It tells me the following: Error submitting changes to the Collector Database. Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information. Why does it tell me that if I have already the primary key defined in the primary table? Thanks for your thoughts! mrclash

      B Offline
      B Offline
      bearfx
      wrote on last edited by
      #2

      This is basically saying you can't autogenerate the command without primary key information. If you want to use the CommandBuilder, you need to be aware of it's limitations. The CommandBuilder classes can be used to build update commands for single-table select queries that include at least one unique column. Your SQL command doesn;t include a unique column, so it cannot be used. Include the primary key in your select query, and it should work, as long as it is a single-table query. If probably looks something like this Select col1, col2, col3 from table1 where col1 = somevalue change it to Select pkey, col1, col2, col3 from table1 where col1 = somevalue If it is not a single-table query, you will need to build your own insert, update, and delete queries using the InsertCommand, UpdateCommand, and DeleteCommand properties.

      1 Reply Last reply
      0
      • M mrclash888

        I am using a dataset on a table with an already defined primary key in an sql server 2000: SqlCommand currentControllerCommand = new SqlCommand(currentControllerSQL,IDGSConnection); SqlDataAdapter currentControllerAdapter = new SqlDataAdapter(currentControllerCommand); DataSet currentControllerDS = new DataSet(); currentControllerAdapter.Fill(currentControllerDS,collector["TargetUsersTable"].ToString()); When later I try to update the table with the changes on the dataset: SqlCommandBuilder cb = new SqlCommandBuilder(currentControllerAdapter); currentControllerAdapter = cb.DataAdapter; currentControllerAdapter.Update(currentControllerDS,collector["TargetUsersTable"]); It tells me the following: Error submitting changes to the Collector Database. Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information. Why does it tell me that if I have already the primary key defined in the primary table? Thanks for your thoughts! mrclash

        J Offline
        J Offline
        Jim Conigliaro
        wrote on last edited by
        #3

        What does the select command look like?

        Jim Conigliaro jconigliaro@ieee.org
        http://www.jimconigliaro.com

        M 1 Reply Last reply
        0
        • J Jim Conigliaro

          What does the select command look like?

          Jim Conigliaro jconigliaro@ieee.org
          http://www.jimconigliaro.com

          M Offline
          M Offline
          mrclash888
          wrote on last edited by
          #4

          SELECT ID,Email,New FROM Collector_Users Where ID is a primary key...

          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