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. Database & SysAdmin
  3. Database
  4. problem with Oracle and ole auto generate update

problem with Oracle and ole auto generate update

Scheduled Pinned Locked Moved Database
helpdatabaseoraclecomannouncement
8 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
    maryam saboor
    wrote on last edited by
    #1

    hi every body! I use Oracle and for connection management I use OLEDB, the problem is where I want to do Update. the Update command is generated by an OleDBDataAdapter as the code below:

    Public Sub UpdateData(ByVal oiDataSet As DataSet, ByVal siSQL As String, Optional ByVal siTableName As String = Nothing)

        Dim oDataAdapter As New OleDbDataAdapter
    
        Try
            If mbPiDisposed = True Then
                Throw New ObjectDisposedException(msPiModuleName, "This object has already been disposed. You cannot reuse it.")
            End If
    
            oDataAdapter.SelectCommand = New OleDbCommand(siSQL, mcnPiConnection, mtrPiTransaction)
    
            Dim oCommandBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(oDataAdapter)
    
            If siTableName = Nothing Then
                oDataAdapter.Update(oiDataSet)
            Else
                oDataAdapter.Update(oiDataSet, siTableName)
            End If
        Catch ex As Exception
            Throw New Exception(msPiExceptionMessage, ex)
        Finally
        End Try
    End Sub
    

    when I call this Sub (I pass a simple "SELECT * FROM TABLE_NAME" and Updated data as "oiDataSet" to the OleDBDataAdapter as shown above) this error is shown: "Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information" I searched the Internet But every one said that you may have not define a primary key, but my table has one!! I should say the INSERT commands are OK, the problem is with UPDATE and DELETE commands. every suggestion would be appreciated

    M M 2 Replies Last reply
    0
    • M maryam saboor

      hi every body! I use Oracle and for connection management I use OLEDB, the problem is where I want to do Update. the Update command is generated by an OleDBDataAdapter as the code below:

      Public Sub UpdateData(ByVal oiDataSet As DataSet, ByVal siSQL As String, Optional ByVal siTableName As String = Nothing)

          Dim oDataAdapter As New OleDbDataAdapter
      
          Try
              If mbPiDisposed = True Then
                  Throw New ObjectDisposedException(msPiModuleName, "This object has already been disposed. You cannot reuse it.")
              End If
      
              oDataAdapter.SelectCommand = New OleDbCommand(siSQL, mcnPiConnection, mtrPiTransaction)
      
              Dim oCommandBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(oDataAdapter)
      
              If siTableName = Nothing Then
                  oDataAdapter.Update(oiDataSet)
              Else
                  oDataAdapter.Update(oiDataSet, siTableName)
              End If
          Catch ex As Exception
              Throw New Exception(msPiExceptionMessage, ex)
          Finally
          End Try
      End Sub
      

      when I call this Sub (I pass a simple "SELECT * FROM TABLE_NAME" and Updated data as "oiDataSet" to the OleDBDataAdapter as shown above) this error is shown: "Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information" I searched the Internet But every one said that you may have not define a primary key, but my table has one!! I should say the INSERT commands are OK, the problem is with UPDATE and DELETE commands. every suggestion would be appreciated

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      At a guess I would say that your select statement does not include the primary key for the table. As a general recommendation I suggest you learn about Data Access Layer (DAL) and not rely on the adapter auto generation tools, you will be a better developer faster if you understand the tools you are using.

      M 1 Reply Last reply
      0
      • M Mycroft Holmes

        At a guess I would say that your select statement does not include the primary key for the table. As a general recommendation I suggest you learn about Data Access Layer (DAL) and not rely on the adapter auto generation tools, you will be a better developer faster if you understand the tools you are using.

        M Offline
        M Offline
        maryam saboor
        wrote on last edited by
        #3

        thank you for reply, yes I have not the Where Clause in my statement. if it was my choice, yes! as you said, it's the worst way to let the tools do the job!! but this code was a part of an old, big and critical project which my boss prefers not to change the code unless it's necessary!!! so I want to be sure there is not any other way except using "Where" and pass primary keys!! so I can content the boss to change the code!! :doh: by the way thanks for your kind recommendation, ANOTHER HELP EQUEST: do you know any other way??;) (my boss is so hard!)

        M 1 Reply Last reply
        0
        • M maryam saboor

          thank you for reply, yes I have not the Where Clause in my statement. if it was my choice, yes! as you said, it's the worst way to let the tools do the job!! but this code was a part of an old, big and critical project which my boss prefers not to change the code unless it's necessary!!! so I want to be sure there is not any other way except using "Where" and pass primary keys!! so I can content the boss to change the code!! :doh: by the way thanks for your kind recommendation, ANOTHER HELP EQUEST: do you know any other way??;) (my boss is so hard!)

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Sorry, I would look at adding the primary key to the select statement as the minimal intervention required. Alternatively I would look if there is a combination of existing fields that could be used as a primary key and write my own update method. How can it be "old and critical" if your update does not work?

          M 1 Reply Last reply
          0
          • M Mycroft Holmes

            Sorry, I would look at adding the primary key to the select statement as the minimal intervention required. Alternatively I would look if there is a combination of existing fields that could be used as a primary key and write my own update method. How can it be "old and critical" if your update does not work?

            M Offline
            M Offline
            maryam saboor
            wrote on last edited by
            #5

            thanks, about your question: we are moving the data base from SQL Server to Oracle. every thing goes OK by SQL, but this problem is by Oracle ;)

            M 1 Reply Last reply
            0
            • M maryam saboor

              thanks, about your question: we are moving the data base from SQL Server to Oracle. every thing goes OK by SQL, but this problem is by Oracle ;)

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              Ok then it is the different databases, you may have not set a primary key on the table to be updated in Oracle

              Never underestimate the power of human stupidity RAH

              1 Reply Last reply
              0
              • M maryam saboor

                hi every body! I use Oracle and for connection management I use OLEDB, the problem is where I want to do Update. the Update command is generated by an OleDBDataAdapter as the code below:

                Public Sub UpdateData(ByVal oiDataSet As DataSet, ByVal siSQL As String, Optional ByVal siTableName As String = Nothing)

                    Dim oDataAdapter As New OleDbDataAdapter
                
                    Try
                        If mbPiDisposed = True Then
                            Throw New ObjectDisposedException(msPiModuleName, "This object has already been disposed. You cannot reuse it.")
                        End If
                
                        oDataAdapter.SelectCommand = New OleDbCommand(siSQL, mcnPiConnection, mtrPiTransaction)
                
                        Dim oCommandBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(oDataAdapter)
                
                        If siTableName = Nothing Then
                            oDataAdapter.Update(oiDataSet)
                        Else
                            oDataAdapter.Update(oiDataSet, siTableName)
                        End If
                    Catch ex As Exception
                        Throw New Exception(msPiExceptionMessage, ex)
                    Finally
                    End Try
                End Sub
                

                when I call this Sub (I pass a simple "SELECT * FROM TABLE_NAME" and Updated data as "oiDataSet" to the OleDBDataAdapter as shown above) this error is shown: "Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information" I searched the Internet But every one said that you may have not define a primary key, but my table has one!! I should say the INSERT commands are OK, the problem is with UPDATE and DELETE commands. every suggestion would be appreciated

                M Offline
                M Offline
                maryam saboor
                wrote on last edited by
                #7

                I found where is the problem. after all discussions, about how can sombody send an Update command to data base!!! the key is here: Every thing was ok in code and table difinitions. just in connection string a property should be defined: "OLEDB.NET=True" was easy?? :-\

                E 1 Reply Last reply
                0
                • M maryam saboor

                  I found where is the problem. after all discussions, about how can sombody send an Update command to data base!!! the key is here: Every thing was ok in code and table difinitions. just in connection string a property should be defined: "OLEDB.NET=True" was easy?? :-\

                  E Offline
                  E Offline
                  ExploreLife
                  wrote on last edited by
                  #8

                  :-\ That's a perfect answer!!!!How did you know that? hard work for me ;P

                  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