Link to home
Start Free TrialLog in
Avatar of mathieu_cupryk
mathieu_cuprykFlag for Canada

asked on

Need a message.

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

Create PROCEDURE [dbo].[RG_sp_DeleteDatePeriod]
(
      @iId int
)
AS
BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
      DELETE FROM RF_DatePeriod WHERE @iId NOT IN (SELECT DatePeriodId FROM RF_xDatePeriodInFormat)

END

I need to display a message say Cannot delete DatePeriodId that belongs to ReportFormat


Msg 547, Level 16, State 0, Procedure RG_sp_DeleteDatePeriod, Line 11
The DELETE statement conflicted with the REFERENCE constraint "FK_xPeriodInFormat_DatePeriodId". The conflict occurred in database "RG_StudyMatt2610", table "dbo.RF_xDatePeriodInFormat", column 'DatePeriodID'.


private void btnDeleteDatePeriod_Click(object sender, EventArgs e)
        {
            if (grdDatePeriods.DisplayLayout.ActiveRow != null)
            {
                if (grdDatePeriods.Selected.Rows.Count == 1)
                {
                    try
                    {
                        Voxco.Data.DatePeriod _dp = Voxco.Data.Manager.DatePeriods.GetObject((int)grdDatePeriods.ActiveRow.Cells["DatePeriodId"].Value);
                        System.Windows.Forms.DialogResult Result = System.Windows.Forms.MessageBox.Show("Are you sure you want to delete?", "Delete DatePeriod",
                        System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question);
                        if (Result == System.Windows.Forms.DialogResult.Yes)
                        {
                            _dp.Delete();  I need a message here. ************************
                            RefreshData();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }


                }
            }
        }

public void Delete()
        {
            VxDbClient _dbClient = SystemDBConnection.CreateSystemDbClient();
            DataSet _ds = _dbClient.ExecuteStoredProc("RG_sp_DeleteDatePeriod",
                new VxDbParameter[]
                {
                    new VxDbParameter(VxDbType.Sql, "@iId", Id)              
 
                });

        }
ASKER CERTIFIED SOLUTION
Avatar of TheAvenger
TheAvenger
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial