We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Data Concurrency in GDBG

Hi Clay,

I have a GDBG which is bound to a DataTable. I am updating the changes done to the GDBG on the RowLeave Event directly to the SQL Database Table. At this point I need to check for data concurrency issues. So I need to pass the old values along with the new values to the stored procedure updating the Database. Below is the Stored Procedure
--------------------------------------------
CREATE Procedure [STRV_SalGradeEnt_UPDATE]

-- Update an existing record in [STRV_SalGradeEnt] table

(
@Code [varchar](9), -- for [STRV_SalGradeEnt].[Code] column
@Coral [bit], -- for [STRV_SalGradeEnt].[Coral] column
@Pearl [bit], -- for [STRV_SalGradeEnt].[Pearl] column
@Diamond [bit], -- for [STRV_SalGradeEnt].[Diamond] column
@nCoral [bit], -- for [STRV_SalGradeEnt].[Coral] column
@nPearl [bit], -- for [STRV_SalGradeEnt].[Pearl] column
@nDiamond [bit] -- for [STRV_SalGradeEnt].[Diamond] column
)

As

Update [dbo].[STRV_SalGradeEnt]

Set
[Coral] = @Coral, [Pearl] = @Pearl, [Diamond] = @Diamond

Where
([Code] = @Code) AND [Coral] = @nCoral AND [Pearl] = @nPearl AND [Diamond] = @nDiamond
GO

--------------------------------------------

So as per the above stored procedure i need to pass the old values along with the changed values. I am doing this in the RowLeave Event like below
----------------------------------------------

private void libgrid_RowLeave(object sender, GridRowEventArgs e)
{

if (this.libgrid.Binder.IsAnyDirtyField() == true) //Check If Any Field has been Modified
{
if (this.libgrid.DataSource.ToString() == "STRV_SalGradeEnt")
{
int RowsAffected=0;
SqlParameter [] param = new SqlParameter[7];
param[0] = new SqlParameter("@Code",SqlDbType.VarChar,9);
param[0].Value = this.libgrid[e.RowIndex,1].Text;;

param[1] = new SqlParameter("@Coral",SqlDbType.Bit,1);
param[1].Value = Convert.ToInt16(Convert.ToBoolean(this.libgrid[e.RowIndex,2].Text));

param[2] = new SqlParameter("@Pearl",SqlDbType.Bit,1);
param[2].Value = Convert.ToInt16(Convert.ToBoolean(this.libgrid[e.RowIndex,3].Text));

param[3] = new SqlParameter("@Diamond",SqlDbType.Bit,1);
param[3].Value = Convert.ToInt16(Convert.ToBoolean(this.libgrid[e.RowIndex,4].Text));


param[4] = new SqlParameter("@nCoral",SqlDbType.Bit,1);
param[4].Value = Convert.ToInt16(Convert.ToBoolean(this.libDS.Tables["STRV_SalGradeEnt"].Rows[e.RowIndex-1]["Coral"].ToString()));

param[5] = new SqlParameter("@nPearl",SqlDbType.Bit,1);
param[5].Value = Convert.ToInt16(Convert.ToBoolean(this.libDS.Tables["STRV_SalGradeEnt"].Rows[e.RowIndex]["Pearl"].ToString()));

param[6] = new SqlParameter("@nDiamond",SqlDbType.Bit,1);
param[6].Value = Convert.ToInt16(Convert.ToBoolean(this.libDS.Tables["STRV_SalGradeEnt"].Rows[e.RowIndex]["Diamond"].ToString()));

retval = conn.ExecNonQuery("STRV_SalGradeEnt_UPDATE", out RowsAffected,CommandType.StoredProcedure,ref ErrMsg,param);
if (retval == false)
{
MessageBox.Show(this,ErrMsg,"Library Data Check",MessageBoxButtons.OK,MessageBoxIcon.Warning);
e.Cancel = true;
}
else
{
if (RowsAffected == 0)
{
DialogResult result;
result = MessageBox.Show(this,"Record Could Not be Updated. Another User may have Modified the Data!Click Yes to Refresh Changes.","Library Data Check",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
e.Cancel = true;
}
}
}
}

----------------------------------------------

In the above code I do not seem to be getting the old values of the datatable. Can you figure out the error, also if you have any article or post on concurrency handling, please let me know

Thanks in Advance,
Osden Pereira,


4 Replies

AD Administrator Syncfusion Team August 22, 2005 12:26 PM UTC

Have you set grid.Binder.DirectSaveCellInfo = true or have you explicitly called grid.Binder.EndEdit or currencyManager.EndEdit for any particular reason? If so, such actions will puch the changes to the DataTable before RowLeave is hit, and this might explain the behavior you are seeing.


OP Osden Pereira August 23, 2005 08:41 AM UTC

Hi Clay, I have not set any of the above things u mentioned, also i am not using a currencymanager. I have the following events registered for the GDBG: -------------------------------------------- this.libgrid.RowEnter this.libgrid.RowEditing this.libgrid.RowLeave this.libgrid.CurrentCellActivating this.libgrid.CurrentCellActivated this.libgrid.CurrentCellActivateFailed this.libgrid.Model.PasteCellText this.libgrid.CurrentCellKeyPress ---------------------------------------------


OP Osden Pereira August 23, 2005 08:45 AM UTC

Also find attached the class file of the GDBG Form. Library_2924.zip


AD Administrator Syncfusion Team August 23, 2005 10:02 AM UTC

You can probably get this to work by using the grid.RowEnter event to cache the original values of your datarow, and then in RowLeave, used these cached values for the original values and not try to get them from the DataTable.

Loader.
Live Chat Icon For mobile
Up arrow icon