Information générale
Catégorie:
The Mere Mortals .NET Framework
I put some code in the Business.cs file under the HookSetDefaultValues() method to set the Guids. The code steps through the dataset to find the Guid (the first record in my data). The only problem is that if there are default values for the table, it overrides the HookSetDefaultValues() in the business object and does not call the base function. I add base.HookSetDefaultValues(dataRow) and everything works fine.
protected override void HookSetDefaultValues(DataRow dataRow)
{ // We need to make sure the Guids are not null
base.HookSetDefaultValues(dataRow);
for (int iCol = 0; iCol < dataRow.Table.Columns.Count; iCol++)
{
if (dataRow.Table.Columns[iCol].DataType.ToString() == "System.Guid"
&& !(dataRow[iCol] is Guid))
{
if (dataRow.Table.Columns[iCol].ColumnName == this.PrimaryKey)
{ // This is as good a place to assign the primary key as any
dataRow[iCol] = Guid.NewGuid();
break;
}
}
}
}
Jeff
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement