ConstraintException Only being thrown once

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In my application I fill a DataGrid with data from a TypedDataset base on a
users Search Pattern.

The first time I execute the Fill it throws an ConstraintException, which is
expected. This allows the grid to flag the rows that have errors. When the
user enters a new Search Pattern I execute a Clear() on the table in the data
set I am using and execute the fill with the new parameter. Except this time
no Exception is thrown. There should be an Exception, but there isn't. Do I
have to reset something in order for the Exception to always be thrown?

I even checked the HasErrors flag and it is false. Any help would be
appreciated.

Here is the code I execute when the user clicks the Find Now button:

public void FillPartyMapDataSet( string parameter )
{
string searchPattern = parameter.Trim();
if( searchPattern.Equals( string.Empty ) )
return;

if( searchPattern != _lastSearchPattern )
{
DataSet.PARTY_CREDIT_GROUP_MAP.Clear();
_dataLoaded = false;
}

_lastSearchPattern = searchPattern;

if( !_dataLoaded )
{
IDataParameter[] dp = this.daPARTY_CREDIT_GROUP_MAP.GetFillParameters();
dp[ 0 ].Value = _lastSearchPattern;
this.daPARTY_CREDIT_GROUP_MAP.Fill( this.DataSet );
_dataLoaded = true;
}
}
 
Hi Steven,

Check dataset.EnforceConstraints property.
I think it goes false when dataset constraints check falls and you have to
reset it manually.
 
Thanks, but that wasn't it. Any other thoughts?

--
Thanks,

Steven Perry


Miha Markic said:
Hi Steven,

Check dataset.EnforceConstraints property.
I think it goes false when dataset constraints check falls and you have to
reset it manually.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

Steven Perry said:
In my application I fill a DataGrid with data from a TypedDataset base on
a
users Search Pattern.

The first time I execute the Fill it throws an ConstraintException, which
is
expected. This allows the grid to flag the rows that have errors. When
the
user enters a new Search Pattern I execute a Clear() on the table in the
data
set I am using and execute the fill with the new parameter. Except this
time
no Exception is thrown. There should be an Exception, but there isn't.
Do I
have to reset something in order for the Exception to always be thrown?

I even checked the HasErrors flag and it is false. Any help would be
appreciated.

Here is the code I execute when the user clicks the Find Now button:

public void FillPartyMapDataSet( string parameter )
{
string searchPattern = parameter.Trim();
if( searchPattern.Equals( string.Empty ) )
return;

if( searchPattern != _lastSearchPattern )
{
DataSet.PARTY_CREDIT_GROUP_MAP.Clear();
_dataLoaded = false;
}

_lastSearchPattern = searchPattern;

if( !_dataLoaded )
{
IDataParameter[] dp =
this.daPARTY_CREDIT_GROUP_MAP.GetFillParameters();
dp[ 0 ].Value = _lastSearchPattern;
this.daPARTY_CREDIT_GROUP_MAP.Fill( this.DataSet );
_dataLoaded = true;
}
}

--

Thanks,

Steven Perry
 
Hi Steven,

You can try to add a breakpoint before refilling the DataSet and check if
the contraints in the target DataTable still exists.

Also, you're using this.daPARTY_CREDIT_GROUP_MAP.Fill( this.DataSet ); to
fill the data, this could be wrong because I didn't see table mapping set
in your code. Will another table be created and data filled to that table?
You can check the DataSet.Table collection to see if a new table is added.
If so, you can try to specify the table you're filling.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
The da is maintained by Visual Studio. The TableMapping exists in the
InitializeComponent call for the DataProvider class. I have included it
below:

//
// daPARTY_CREDIT_GROUP_MAP
//
this.daPARTY_CREDIT_GROUP_MAP.SelectCommand =
this.PARTY_CREDIT_GROUP_MAPSelect;
this.daPARTY_CREDIT_GROUP_MAP.TableMappings.AddRange( new
System.Data.Common.DataTableMapping[]
{
new System.Data.Common.DataTableMapping( "Table",
"PARTY_CREDIT_GROUP_MAP", new System.Data.Common.DataColumnMapping[]
{
new System.Data.Common.DataColumnMapping( "GDR_PARTY_ID",
"GDR_PARTY_ID" ),
new System.Data.Common.DataColumnMapping( "CRM_CREDIT_GROUP_ID",
"CRM_CREDIT_GROUP_ID" ),
new System.Data.Common.DataColumnMapping(
"CRM_CRED_GRP_APPROVAL_STATUS", "CRM_CRED_GRP_APPROVAL_STATUS" ),
new System.Data.Common.DataColumnMapping(
"CRM_CRED_GRP_APPROVAL_DATE", "CRM_CRED_GRP_APPROVAL_DATE" ),
new System.Data.Common.DataColumnMapping( "CRM_CRED_GRP_APPROVER",
"CRM_CRED_GRP_APPROVER" ),
new System.Data.Common.DataColumnMapping( "UPD_USER", "UPD_USER" ),
new System.Data.Common.DataColumnMapping( "UPD_TIMESTAMP",
"UPD_TIMESTAMP" ),
new System.Data.Common.DataColumnMapping(
"SOURCE_SYSTEM_DATA_SOURCE", "SOURCE_SYSTEM_DATA_SOURCE" ),
new System.Data.Common.DataColumnMapping( "SOURCE_SYS_PARTY_NAME",
"SOURCE_SYS_PARTY_NAME" ),
new System.Data.Common.DataColumnMapping( "CRM_CREDIT_GROUP_NAME",
"CRM_CREDIT_GROUP_NAME" ),
new System.Data.Common.DataColumnMapping( "RU_NAME", "RU_NAME" ),
new System.Data.Common.DataColumnMapping( "PARTY_LEGAL_NAME",
"PARTY_LEGAL_NAME" ),
new System.Data.Common.DataColumnMapping( "PARTY_CUSIP",
"PARTY_CUSIP" ),
new System.Data.Common.DataColumnMapping( "PARTY_ISIN", "PARTY_ISIN" ),
new System.Data.Common.DataColumnMapping( "PARTY_SEDOL",
"PARTY_SEDOL" )
} )
} );
this.daPARTY_CREDIT_GROUP_MAP.UpdateCommand =
this.PARTY_CREDIT_GROUP_MAPUpdate;
//
// PARTY_CREDIT_GROUP_MAPSelect
//
this.PARTY_CREDIT_GROUP_MAPSelect.CommandText =
"SELECT pssi.SOURCE_SYSTEM_DATA_SOURCE, CASE WHEN rpu.RU_NAME IS NULL
THEN pssi.SOURCE_SYSTEM_DATA_SOURCE ELSE rpu.RU_NAME END AS RU_NAME, " +
"pssi.SOURCE_SYS_PARTY_NAME, p.PARTY_LEGAL_NAME, p.PARTY_CUSIP,
p.PARTY_ISIN, p.PARTY_SEDOL, cgr.CRM_CREDIT_GROUP_NAME, pcgm.GDR_PARTY_ID, " +
"pcgm.CRM_CREDIT_GROUP_ID, pcgm.CRM_CRED_GRP_APPROVAL_STATUS,
pcgm.CRM_CRED_GRP_APPROVAL_DATE, pcgm.CRM_CRED_GRP_APPROVER, pcgm.UPD_USER, "
+
"pcgm.UPD_TIMESTAMP " +
"FROM (((GDR_DATA.PARTY_CREDIT_GROUP_MAP pcgm INNER JOIN
GDR_DATA.PARTY_SOURCE_SYSTEM_INFO pssi ON pcgm.GDR_PARTY_ID =
pssi.GDR_PARTY_ID) " +
"INNER JOIN GDR_DATA.CRM_CREDIT_GROUP_REF cgr ON
pcgm.CRM_CREDIT_GROUP_ID = cgr.CRM_CREDIT_GROUP_ID) " +
"LEFT JOIN GDR_DATA.PARTY p ON pcgm.GDR_PARTY_ID = p.GDR_PARTY_ID) " +
"LEFT JOIN GXPSTG.RPU_REF rpu ON pssi.SOURCE_SYSTEM_DATA_SOURCE =
rpu.RU_ID " +
"WHERE UPPER( pssi.SOURCE_SYS_PARTY_NAME ) LIKE UPPER( :SEARCH_PATTERN )
ESCAPE '!'";
this.PARTY_CREDIT_GROUP_MAPSelect.Connection = this._conn;
this.PARTY_CREDIT_GROUP_MAPSelect.Parameters.Add( new
System.Data.OracleClient.OracleParameter( ":SEARCH_PATTERN",
System.Data.OracleClient.OracleType.VarChar, 255, "SEARCH_PATTERN" ) );
//
// PARTY_CREDIT_GROUP_MAPUpdate
//
this.PARTY_CREDIT_GROUP_MAPUpdate.CommandText = @"UPDATE
GDR_DATA.PARTY_CREDIT_GROUP_MAP SET CRM_CREDIT_GROUP_ID =
:CRM_CREDIT_GROUP_ID, CRM_CRED_GRP_APPROVAL_STATUS =
:CRM_CRED_GRP_APPROVAL_STATUS, CRM_CRED_GRP_APPROVAL_DATE =
:CRM_CRED_GRP_APPROVAL_DATE, CRM_CRED_GRP_APPROVER = :CRM_CRED_GRP_APPROVER,
UPD_USER = :UPD_USER, UPD_TIMESTAMP = :UPD_TIMESTAMP WHERE (GDR_PARTY_ID =
:Original_GDR_PARTY_ID)";
this.PARTY_CREDIT_GROUP_MAPUpdate.Connection = this._conn;
this.PARTY_CREDIT_GROUP_MAPUpdate.Parameters.Add( new
System.Data.OracleClient.OracleParameter( ":CRM_CREDIT_GROUP_ID",
System.Data.OracleClient.OracleType.Number, 0,
System.Data.ParameterDirection.Input, false, ((System.Byte)(38)),
((System.Byte)(0)), "CRM_CREDIT_GROUP_ID",
System.Data.DataRowVersion.Current, null ) );
this.PARTY_CREDIT_GROUP_MAPUpdate.Parameters.Add( new
System.Data.OracleClient.OracleParameter( ":CRM_CRED_GRP_APPROVAL_STATUS",
System.Data.OracleClient.OracleType.VarChar, 20,
"CRM_CRED_GRP_APPROVAL_STATUS" ) );
this.PARTY_CREDIT_GROUP_MAPUpdate.Parameters.Add( new
System.Data.OracleClient.OracleParameter( ":CRM_CRED_GRP_APPROVAL_DATE",
System.Data.OracleClient.OracleType.DateTime, 0, "CRM_CRED_GRP_APPROVAL_DATE"
) );
this.PARTY_CREDIT_GROUP_MAPUpdate.Parameters.Add( new
System.Data.OracleClient.OracleParameter( ":CRM_CRED_GRP_APPROVER",
System.Data.OracleClient.OracleType.VarChar, 255, "CRM_CRED_GRP_APPROVER" ) );
this.PARTY_CREDIT_GROUP_MAPUpdate.Parameters.Add( new
System.Data.OracleClient.OracleParameter( ":UPD_USER",
System.Data.OracleClient.OracleType.VarChar, 20, "UPD_USER" ) );
this.PARTY_CREDIT_GROUP_MAPUpdate.Parameters.Add( new
System.Data.OracleClient.OracleParameter( ":UPD_TIMESTAMP",
System.Data.OracleClient.OracleType.DateTime, 0, "UPD_TIMESTAMP" ) );
this.PARTY_CREDIT_GROUP_MAPUpdate.Parameters.Add( new
System.Data.OracleClient.OracleParameter( ":Original_GDR_PARTY_ID",
System.Data.OracleClient.OracleType.VarChar, 20,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "GDR_PARTY_ID", System.Data.DataRowVersion.Original, null
) );

--
Thanks,

Steven Perry
 
Hi Steven,

From the table mapping code, I didn't see anything wrong. Have you tried
checking if the data adapter is filling to the correct table? It would be
helpful if you can build a small example that can reproduce the problem. So
that I can try to debug on this. Thank you!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top