Results 1 to 9 of 9

Thread: Update Field in table - ODBC Method

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2017
    Posts
    6

    Post Update Field in table - ODBC Method

    Dear Sirs,

    I am not beeing able witht his code to update the field GNP27SNT TO "Y" From Table TSTOBJ.GNP27PF
    Can you kindly help in this isue,

    Thanks in advance


    Dim MyODBCConnection As New OdbcConnection("Driver={Client Access ODBC Driver (32-bit)};" & _
    "System=ASBF4;" & "TRANSLATE=1;" & "Uid=B222;" & "Pwd=Brf3")
    'Open the connection
    MyODBCConnection.Open()

    'Create Data Adapters
    Dim DA0 As OdbcDataAdapter = New OdbcDataAdapter

    ' Create the UpdateCommand.
    Dim cmd As OdbcCommand
    Dim parm As OdbcParameter

    cmd = New OdbcCommand("UPDATE TSTOBJ.GNP27PF SET GNP27SNT = pSnt", MyODBCConnection)
    parm = cmd.Parameters.Add("pSnt", OdbcType.Char, 1, "Y")
    ' parm.SourceVersion = DataRowVersion.Original
    DA0.UpdateCommand = cmd

    MyODBCConnection.Close()
    MyODBCConnection.Dispose()

    End Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Update Field in table - ODBC Method

    Please use formatting tags when posting code snippets for readability.
    Code:
            Dim MyODBCConnection As New OdbcConnection("Driver={Client Access ODBC Driver (32-bit)};" & _
                   "System=ASBF4;" & "TRANSLATE=1;" & "Uid=B222;" & "Pwd=Brf3")
            'Open the connection
            MyODBCConnection.Open()
    
                  'Create Data Adapters
            Dim DA0 As OdbcDataAdapter = New OdbcDataAdapter
          
                  ' Create the UpdateCommand.
            Dim cmd As OdbcCommand
            Dim parm As OdbcParameter
    
            cmd = New OdbcCommand("UPDATE TSTOBJ.GNP27PF SET GNP27SNT = pSnt", MyODBCConnection)
            parm = cmd.Parameters.Add("pSnt", OdbcType.Char, 1, "Y")
            ' parm.SourceVersion = DataRowVersion.Original
            DA0.UpdateCommand = cmd
    
            MyODBCConnection.Close()
            MyODBCConnection.Dispose()
    
        End Sub
    Also, please explain what actually happens when you try to run that code. If there's a compilation error, tell us what the error message is and where it occurs. If there's a run time exception, do the same. Provide us with ALL the relevant information. Don't leave it to use to work out things that you already know.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Update Field in table - ODBC Method

    Mind you, looking more closely at that code, the issue is fairly obvious. It really should have been to you to. Which line of that code do you think is actually saving the data to the database? I suggest that you follow the CodeBank link in my signature below and check out my thread on Retrieving & Saving Data for some ADO.NET code examples for common scenarios.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2017
    Posts
    6

    Re: Update Field in table - ODBC Method

    Quote Originally Posted by jmcilhinney View Post
    Mind you, looking more closely at that code, the issue is fairly obvious. It really should have been to you to. Which line of that code do you think is actually saving the data to the database? I suggest that you follow the CodeBank link in my signature below and check out my thread on Retrieving & Saving Data for some ADO.NET code examples for common scenarios.
    thanks for the reply and sorry for the way i posted the code am still new here and of course thanks for the info will be following the rules next time,

    Actually the code is compiling well no errors but no updates takes place

    Thank you

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2017
    Posts
    6

    Re: Update Field in table - ODBC Method

    of course am not asking to do the code,thats not my target
    i just needed help is the syntax of the update is wrong or missing any info as no error is occuring but also no update as well,
    thank you

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Update Field in table - ODBC Method

    I asked a question:
    Which line of that code do you think is actually saving the data to the database?
    That was intended to (hopefully) lead you to the answer for yourself.

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2017
    Posts
    6

    Re: Update Field in table - ODBC Method

    DA0.UpdateCommand = cmd
    no?

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Update Field in table - ODBC Method

    No. The UpdateCommand of a data adapter is the command that it executes to save rows from a DataTable with a RowState of Modified. That code doesn't actually execute anything. Again, you should check out my CodeBank examples. If you are using a DataTable, you'll see how to save changes from it using a data adapter, if you're not using a DataTable then you shouldn't be using a data adapter at all. You will find an example appropriate to that situation too.

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2017
    Posts
    6

    Re: Update Field in table - ODBC Method

    okey will check it thanks for the help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width