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,
>>> >>>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 >>> >>>