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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. OdbcCommandBuilder for MySQL

OdbcCommandBuilder for MySQL

Scheduled Pinned Locked Moved C#
csharpdatabasemysqlhelpquestion
7 Posts 2 Posters 1 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.
  • A Offline
    A Offline
    adi rusu
    wrote on last edited by
    #1

    Hi, From C# I'm using an OdbcCommandBuilder to generate DELETE, INSERT and UPDATE commands for updating a MySQL table and I receive the following error: "Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information." I thought this was because the table had no primary key. But I checked and it does. Does anyone know another reason why I get this error? Thanks

    A 1 Reply Last reply
    0
    • A adi rusu

      Hi, From C# I'm using an OdbcCommandBuilder to generate DELETE, INSERT and UPDATE commands for updating a MySQL table and I receive the following error: "Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information." I thought this was because the table had no primary key. But I checked and it does. Does anyone know another reason why I get this error? Thanks

      A Offline
      A Offline
      AhsanS
      wrote on last edited by
      #2

      I think that this error is because you are passing a delete command for select statement. Can you please post your code for me to look into?

      A 1 Reply Last reply
      0
      • A AhsanS

        I think that this error is because you are passing a delete command for select statement. Can you please post your code for me to look into?

        A Offline
        A Offline
        adi rusu
        wrote on last edited by
        #3

        Nope, I'm pretty sure it's not that. But here's the code anyway. OdbcDataAdapter adapter = new OdbcDataAdapter(); OdbcCommand comm = new OdbcCommand("SELECT * FROM `" + tableName + "`", connection); adapter.SelectCommand = comm; OdbcCommandBuilder builder = new OdbcCommandBuilder(adapter); adapter.DeleteCommand = builder.GetDeleteCommand(); adapter.InsertCommand = builder.GetInsertCommand(); adapter.UpdateCommand = builder.GetUpdateCommand(); I suppose the insert and update commands don't work either but I get the exception when trying to generate the delete command.

        A 1 Reply Last reply
        0
        • A adi rusu

          Nope, I'm pretty sure it's not that. But here's the code anyway. OdbcDataAdapter adapter = new OdbcDataAdapter(); OdbcCommand comm = new OdbcCommand("SELECT * FROM `" + tableName + "`", connection); adapter.SelectCommand = comm; OdbcCommandBuilder builder = new OdbcCommandBuilder(adapter); adapter.DeleteCommand = builder.GetDeleteCommand(); adapter.InsertCommand = builder.GetInsertCommand(); adapter.UpdateCommand = builder.GetUpdateCommand(); I suppose the insert and update commands don't work either but I get the exception when trying to generate the delete command.

          A Offline
          A Offline
          AhsanS
          wrote on last edited by
          #4

          adapter.DeleteCommand = builder.GetDeleteCommand(); adapter.InsertCommand = builder.GetInsertCommand(); adapter.UpdateCommand = builder.GetUpdateCommand(); In the above lines of code you are trying to get the delete and update commands, but you have not assigned them any where. You have only assigned select command by using adapter.SelectCommand = comm; I hope it helps sort out your problem

          Ahsan Ullah Senior Software Engineer

          A 1 Reply Last reply
          0
          • A AhsanS

            adapter.DeleteCommand = builder.GetDeleteCommand(); adapter.InsertCommand = builder.GetInsertCommand(); adapter.UpdateCommand = builder.GetUpdateCommand(); In the above lines of code you are trying to get the delete and update commands, but you have not assigned them any where. You have only assigned select command by using adapter.SelectCommand = comm; I hope it helps sort out your problem

            Ahsan Ullah Senior Software Engineer

            A Offline
            A Offline
            adi rusu
            wrote on last edited by
            #5

            The Get{Delete,Insert,Update}Command() methods analyze the select command of the data adapter, and generate OdbcCommand objects according to the data returned by the select command. I've checked their CommandText properties during Debug and they seem ok. If I didn't assign them, the error would be something like "use of unassigned command" or another message, but not the message that I get. If you meant something else by assigning the commands, please give me an example. The problem is not with the code but with the database. I know this because it works on one database but it fails on another database with exactly the same structure but from another computer. Could it be the MySql version? Adrian Junior Developer

            A 1 Reply Last reply
            0
            • A adi rusu

              The Get{Delete,Insert,Update}Command() methods analyze the select command of the data adapter, and generate OdbcCommand objects according to the data returned by the select command. I've checked their CommandText properties during Debug and they seem ok. If I didn't assign them, the error would be something like "use of unassigned command" or another message, but not the message that I get. If you meant something else by assigning the commands, please give me an example. The problem is not with the code but with the database. I know this because it works on one database but it fails on another database with exactly the same structure but from another computer. Could it be the MySql version? Adrian Junior Developer

              A Offline
              A Offline
              AhsanS
              wrote on last edited by
              #6

              do a thing comment out the update and delete options and test if select is working alone? If so then the second thing you could check is that you are passing primary key for update and delete commands.

              Ahsan Ullah Senior Software Engineer

              A 1 Reply Last reply
              0
              • A AhsanS

                do a thing comment out the update and delete options and test if select is working alone? If so then the second thing you could check is that you are passing primary key for update and delete commands.

                Ahsan Ullah Senior Software Engineer

                A Offline
                A Offline
                adi rusu
                wrote on last edited by
                #7

                I tried not calling GetDeleteCommand(), GetInsertCommand() and GetUpdateCommand() some time ago and it didn't work. How do I check if I'm passing primary key? Should I adapter.Fill() a table and check if there is a primary key? I can do that. I can generate the commands manually too (but I'd like to avoid that). I'm just trying to understand why the same code works just fine on one computer, but it doesn't on another computer with the same operating system and the same database structure. Would you happen to know if on older versions of MySql, the "select * from <table_name>" command doesn't return key column information even if there are keys in the table?

                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