Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
LHendren
Starting Member
17 Posts |
Posted - 2014-04-01 : 10:26:48
|
I have created a small project to learn how to UPDATE a database table which is part of a VIEW table that populates the GridView. I have been successful in updating a database table bound to the GridView. However, I am attempting the next level of displaying the VIEW and updating one of the TABLEs. MyDatabase.Customer.ID and MyDatabase.CustomerRole.RoleID are the PK’s. I only want to update ONE database table; I am viewing two database tables with VIEW only to provide the user more detailed (background) information.My two tables in the database are Customer and CustomerRole. My view in the database is a combination of the Customer and CustomerRole tables named ViewCustomer. My trigger is named ViewCustomerTrigger. Using the GridView displays the ViewCustomer view via ViewCustomerTableAdapter.Fill(MyDatabaseDataSet.ViewCustomer) , and I want to update the Customer table via CustomerTableAdapter.Update(MyDatabaseDataSet.Customer) I cannot get the Customer table to Update when the form closes.My TRIGGER is this:USE MyDataBaseGOCREATE TRIGGER ViewCustomerTrigger ON ViewCustomerINSTEAD OF UPDATEASIF IS_MEMBER ('db_owner') = 0BEGINSET NOCOUNT ONUPDATE dbo.CustomerSET Fname = I.Name, SName = I.SName,RoleID = I.RoleIDFROM INSERTED I JOIN Customer C ON I.ID = C.IDPRINT 'You must ask your DBA to dropor alter tables!'ROLLBACK TRANSACTIONENDGOMy VB code is this:Public Class Form1Sub New() InitializeComponent() ViewCustomerTableAdapter.Fill(MyDatabaseDataSet.ViewCustomer) ' theVIEW tableEnd SubPrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Close()End SubPrivate Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As FormClosingEventArgs) Handles MyBase.FormClosing Dim view As DevExpress.XtraGrid.Views.Base.BaseView = GridControl1.FocusedView If Not (view.PostEditor() And view.UpdateCurrentRow()) Thene.Cancel = TrueReturnEnd If CustomerTableAdapter.Update(MyDatabaseDataSet.Customer) ' the database table End SubEnd Class |
|
ScottPletcher
Aged Yak Warrior
550 Posts |
Posted - 2014-04-01 : 12:37:00
|
You're rolling back the UPDATE.Also, you can't use a PRINT statement in a trigger. |
|
|
|
|
|