Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 8th, 2004, 04:43 AM
Registered User
 
Join Date: Nov 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default update access db with dataset

Hi,
This is here my first post, I hope you can help me. What I do in my script part1: I extract 1 access table to a dataset. part2: I make changes to dat dataset, I add and update records. part 3: I try to update the origenal DB with the dataset, but here he gives an error: 'Operation must use an updateable query.' Who can help?

Thanks,
Dennis


Code:
'PART 1: Acces database connection
'------------------------
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
                   "Data Source=C:\Inetpub\wwwroot\q_checks.mdb"

dbConnection = New OledbConnection(connectionString)
dbConnection.Open()

query_tablesegments = "SELECT * FROM TABLESEGMENTS"

dataAdapter_tablesegments = New OledbDataAdapter(query_tablesegments, dbConnection)
dataAdapter_tablesegments.Fill(Access_DS, "TableSegments")

Access_DG_TS.DataSource = Access_DS.tables("TableSegments")
Access_DG_TS.DataBind()

'PART2: Changes made in the dataset
'----------------------------------    
For Each xml_Row_ts In Xml_DS.TABLES("TABLESEGMENT").Rows

            newRow = Access_DS.tables("TableSegments").NewRow()


            strExpr = "MCO_CODE = '" & xml_Row_ts.Item("MCO_CODE") & "'" _
                     & " AND MONTH_CODE = '" & xml_Row_ts.Item("MONTH_CODE") & "'" _
                     & " AND TABLE_NAME = '" & xml_Row_ts.Item("TABLENAME") & "'"

            selectedRows = Access_DS.tables("TableSegments").select(strExpr)

            'If Row doesn't exist
            if selectedRows.Length = 0 then

                newRow("TABLE_NAME") = xml_Row_ts.Item("TABLENAME")
                newRow("MCO_CODE") =   xml_Row_ts.Item("MCO_CODE")
                newRow("MONTH_CODE") = xml_Row_ts.Item("MONTH_CODE")
                if (location = "MECH") then
                    newRow("LAST_UPDATE_MECH") = xml_Row_ts.Item("SYS_DATE")
                    newRow("VERSION_MECH") = xml_Row_ts.Item("VERSION")
                    newRow("RECORDS_MECH") = xml_Row_ts.Item("RECORDS")

                    'newRow("LAST_UPDATE_CUST") =
                    newRow("VERSION_CUST") = 0
                    newRow("RECORDS_CUST") = 0
                else
                    newRow("LAST_UPDATE_CUST") = xml_Row_ts.Item("SYS_DATE")
                    newRow("VERSION_CUST") = xml_Row_ts.Item("VERSION")
                    newRow("RECORDS_CUST") = xml_Row_ts.Item("RECORDS")

                    'newRow("LAST_UPDATE_MECH") =
                    newRow("VERSION_MECH") = 0
                    newRow("RECORDS_MECH") = 0
                end if
                Access_DS.tables("TableSegments").Rows.Add(newRow)

                'teslabel only needed for testing
                testlabel.text = testlabel.text & "<BR>" & strExpr


            end if

            'If Row already exist
            if selectedRows.Length = 1 then
                if (location = "MECH") then
                    selectedRows(0).Item("LAST_UPDATE_MECH") = xml_Row_ts.Item("SYS_DATE")
                    selectedRows(0).Item("VERSION_MECH") = xml_Row_ts.Item("VERSION")
                    selectedRows(0).Item("RECORDS_MECH") = xml_Row_ts.Item("RECORDS")
                else
                    selectedRows(0).Item("LAST_UPDATE_CUST") = xml_Row_ts.Item("SYS_DATE")
                    selectedRows(0).Item("VERSION_CUST") = xml_Row_ts.Item("VERSION")
                    selectedRows(0).Item("RECORDS_CUST") = xml_Row_ts.Item("RECORDS")
                end if
            end if
Next


'PART3: Update origenal access DB          Should work, but doesn't work...
'-------------------------------------------------------------------
      Dim commandBuilder As OleDbCommandBuilder

      commandBuilder = New OleDbCommandBuilder(dataAdapter_tablesegments)

      dataAdapter_tablesegments.Update(Access_DS,"TableSegments")  'error message: not an update-able query?





Similar Threads
Thread Thread Starter Forum Replies Last Post
saving a dataset into access db igalk474 ADO.NET 3 July 21st, 2007 05:28 AM
update db from dataset nikosnyc VS.NET 2002/2003 1 July 2nd, 2006 06:27 PM
how to edit and update my access db using asp.net method ASP.NET 1.0 and 1.1 Basics 4 April 25th, 2005 03:03 PM
Dataset Merge then DB Update druid2112 ADO.NET 0 October 4th, 2004 08:44 AM
ASP form to email & update Access db seala Classic ASP Basics 3 July 22nd, 2003 01:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.