General information
Category:
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
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only