Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Error trying to save changed web data
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Error trying to save changed web data
Divers
Thread ID:
00893053
Message ID:
00893053
Vues:
58
I am still way too new at this...
I have a Web Form and I'm trying to save my edits, trying to update the table my dataset is based on... An access table on my web directory.

I am able to navigate the table but when I try to UPDATE the data it doesn't work.
My TRY/CATCH is catching an exception.
How do I find out what the exception is?

I believe the line at fault is:
oledbDA.UpdateCommand.CommandText = 
"UPDATE Contacts SET Company= MyCompany WHERE Unique_ID = MyContacts_Unique_ID"
My code looks like this (please feel free to educate me... I know I need it):
Public Class WebForm1
    Inherits System.Web.UI.Page
    Dim sqlConn As SqlConnection
    Dim oledbConn As OleDbConnection
    Dim oledbDA As OleDbDataAdapter
    Dim oledbDS As DataSet
    Dim oledbDR As DataRow

    Public strWhereClause As String
    Public dsLookup As New DataSet


#Region " Web Form Designer Generated Code "
#End Region

#Region " Page_Load/Clear/ShowRecord/RadioButtonList/Page_Unload/Exit "
    Private Sub Page_Load(ByVal sender As System.Object, 
                        ByVal e As System.EventArgs) Handles MyBase.Load
        Trace.Write("Page_Load", "We're in the Page_Load event!")
        'RML 03/26/2004 - Access connection information
        oledbConn = New OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;
data source=C:\Inetpub\wwwroot\Omnia_Web_Act\data\OmniaAct.mdb")
        
        oledbDA = New OleDbDataAdapter("SELECT * FROM Contacts", oledbConn)
        
        'oledbDA = New OleDbDataAdapter
        oledbDA.SelectCommand.CommandText = "SELECT * FROM Contacts"

        'oledbDA.UpdateCommand.CommandText = ""
        'oledbDA.InsertCommand.CommandText = ""
        'oledbDA.DeleteCommand.CommandText = ""

        oledbDS = New DataSet

        oledbDA.Fill(oledbDS, "Contacts")

        'Dim oledbDR As DataRow
        ShowRecord(Session("intContacts_CurrentRecord"), Session("intContacts_Unique_ID"))

        For Each oledbDR In oledbDS.Tables("Contacts").Rows
            lstContacts.Items.Add(oledbDR.Item("Contact"))
        Next

        Dim oledbDC As DataColumn
        For Each oledbDC In oledbDS.Tables("Contacts").Columns
            lstColumnsInContacts.Items.Add(oledbDC.ColumnName)
        Next
    End Sub

'----------------------------

    Private Sub btnSaveContact_Click(ByVal sender As System.Object, 
                ByVal e As System.EventArgs) Handles btnSaveContact.Click
        Trace.Write("SaveContact_Click", "We're in the SaveContact_Click event")
        Trace.Write("SaveContact_Click", "lAdding = " & Session("lAdding"))
        'put save contact code here
        'Save the information currently displayed on the top half of the screen
        Dim UpdateResult As Integer = -1
        Dim MyContacts_Unique_ID As Integer
        MyContacts_Unique_ID = Session("intContacts_Unique_ID")
        Dim MyCompany As String
        MyCompany = Me.txtCompany.Text
        Trace.Write("SaveContact_Click", "MyCompany = " & MyCompany)

        If Session("lAdding") = True Then
            ' ---- NON-RELAVENT CODE REMOVED ----
        Else
            Trace.Write("SaveContact_Click", 
            "We're in the SaveContact_Click event - lAdding False - 
            Updating Existing data")

            'updating existing data
            Try
                Trace.Write("SaveContact_Click", "In Update Try")

                oledbDS.Tables(0).Rows(Session("intContacts_CurrentRecord")).Item("Company") = 
                Me.txtCompany.Text

            ' ---- NON-RELAVENT CODE REMOVED ----

                Trace.Write("SaveContact_Click", "In Update Try - 
                before - oledbDA.InsertCommand.CommandText")

                oledbDA.UpdateCommand.CommandText = 
                "UPDATE Contacts SET Company= MyCompany 
                WHERE Unique_ID = MyContacts_Unique_ID"


                Trace.Write("SaveContact_Click", 
                "oledbDA.UpdateCommand.CommandText = " & 
                oledbDA.UpdateCommand.CommandText)

                UpdateResult = oledbDA.Update(oledbDS)
                oledbDS.AcceptChanges()
                oledbDA.Fill(oledbDS)
            Catch ex As System.Exception
                Trace.Write("SaveContact_Click", "In Update Exception")
            Finally
                '
            End Try
        End If
        Session("lAdding") = False
        Trace.Write("SaveContact_Click", "lAdding = " & Session("lAdding"))
        ShowRecord(Session("intContacts_CurrentRecord"), Session("intContacts_Unique_ID"))
    End Sub
I hope that's enough for someone to give me the insight I need to get this working.

TIA,
Rick
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform