Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Error trying to save changed web data
Message
 
À
08/04/2004 21:15:28
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00893053
Message ID:
00893524
Vues:
19
Hi Bonnie,
The line the error occurs on is
UpdateResult = oledbDA.Update(oledbDS, "Contacts")

I get there by
Imports System
Imports System.Data
Imports System.Data.OleDb

Public Class WebForm1
    Inherits System.Web.UI.Page
    Dim oledbConn As OleDbConnection
    Dim oledbDA As OleDbDataAdapter
    Dim oledbDS As DataSet
    Dim oledbDR As DataRow
    Dim oledbCMD As OleDbCommand

#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
        oledbCMD = New OleDbCommand

        ' Create the SelectCommand.
        oledbCMD = New OleDbCommand("SELECT * FROM Contacts", oledbConn)
        oledbCMD.Parameters.Add("@Company", OleDbType.VarChar, 50)
        oledbCMD.Parameters.Add("@Contact", OleDbType.VarChar, 50)
        oledbDA.SelectCommand = oledbCMD

        ' Create the InsertCommand.
        oledbCMD = New OleDbCommand("INSERT INTO Contacts (Company, Contact) " & _
                             "VALUES (@Company, @Contact)", oledbConn)
        oledbCMD.Parameters.Add("@Company", OleDbType.Char, 50, "Company")
        oledbCMD.Parameters.Add("@Contact", OleDbType.VarChar, 50, "Contact")
        oledbDA.InsertCommand = oledbCMD

        ' Create the UpdateCommand.
        oledbCMD = New OleDbCommand("UPDATE Contacts SET Company= MyCompany
WHERE Unique_ID = MyContacts_Unique_ID", oledbConn)
        oledbCMD.Parameters.Add("@Company", OleDbType.Char, 50, "Company")
        oledbCMD.Parameters.Add("@Contact", OleDbType.VarChar, 50, "Contact")
        oledbDA.UpdateCommand = oledbCMD

        oledbDS = New DataSet
        oledbDA.Fill(oledbDS, "Contacts")

        ShowRecord(Session("intContacts_CurrentRecord"), Session("intContacts_Unique_ID"))

    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)
        Trace.Write("SaveContact_Click", "MyContacts_Unique_ID = " & MyContacts_Unique_ID)

        If Session("lAdding") = True Then
            Trace.Write("SaveContact_Click", 
            "We're in the SaveContact_Click event - lAdding True - 
            inserting new data")
            'inserting new data
            Try
                Trace.Write("SaveContact_Click", "In Insert Try - 
                before - oledbDA.InsertCommand.CommandText")
            Catch ex As System.Exception
                Trace.Write("SaveContact_Click", "In Insert Exception - ex=" & ex.Message)
            Finally
            End Try
        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
                '-------------------------------

                oledbDR("Company") = Me.txtCompany.Text & "-1"

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

                Trace.Write("SaveContact_Click", 
                        "oledbDR('Company') = " & oledbDR("Company"))

                Trace.Write("SaveContact_Click", "In Update Try - before - 
                        UpdateResult = oledbDA.Update(oledbDS)")

                UpdateResult = oledbDA.Update(oledbDS, "Contacts")

                Trace.Write("SaveContact_Click", "In Update Try - after - 
                        UpdateResult = oledbDA.Update(oledbDS)")

'---------------------------------------------------------
'----I followed the example from 
'----"Updating the Database with a DataAdapter and the DataSet" ------
'---------------------------------------------------------


                'oledbDS.AcceptChanges()
                'oledbDA.Fill(oledbDS)
            Catch ex As System.Exception
                Trace.Write("SaveContact_Click", "In Update Exception - ex=" & ex.Message)
                Trace.Write("SaveContact_Click", "oledbDA.UpdateCommand.CommandText = " & 
oledbDA.UpdateCommand.CommandText)
                '
            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
>Rick,
>
>What line is it erroring out on?
>
>~~Bonnie
>
>
>>Hector,
>>Thank you for helping me.
>>I am now able to see what the exception is.
>>I've made several adjustments to my program, but it's still not working.
>>I followed the example in the help system, but I keep getting the message,
>>"Update unable to find TableMapping['Table'] or DataTable 'Table'."
>>
>>Do you have any idea why this is?
>>
>>Rick
>>
>>'----example from the help system --- "Updating the Database with a DataAdapter and the DataSet" ------
>>'Dim catDA As OleDbDataAdapter = New OleDbDataAdapter("SELECT CategoryID, CategoryName FROM Categories", nwindConn)
>>'catDA.UpdateCommand = New OleDbCommand("UPDATE Categories SET CategoryName = ? " & _
>>' "WHERE CategoryID = ?", nwindConn)
>>'catDA.UpdateCommand.Parameters.Add("@CategoryName", OleDbType.VarChar, 15, "CategoryName")
>>'
>>'Dim workParm As OleDbParameter = catDA.UpdateCommand.Parameters.Add("@CategoryID", OleDbType.Integer)
>>'workParm.SourceColumn = "CategoryID"
>>'workParm.SourceVersion = DataRowVersion.Original
>>'
>>'Dim catDS As DataSet = New DataSet
>>'catDA.Fill(catDS, "Categories")
>>'
>>'Dim cRow As DataRow = catDS.Tables("Categories").Rows(0)
>>'cRow("CategoryName") = "New Category"
>>'
>>'catDA.Update(catDS)
>>'---------------------------------------------------------
>>
>>>>How do I find out what the exception is?
>>>
>>>Try using a TRY/CATCH block:
>>>
>>>
>>>
>>>try
>>>	oledbDA.UpdateCommand.CommandText =
>>>"UPDATE Contacts SET Company= MyCompany WHERE Unique_ID = MyContacts_Unique_ID"
>>>catch ex as exception
>>>	' The value of ex.message will tell you the error
>>>	Response.Write(ex.message)
>>>end try
>>>
>>>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform