Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using GUID as PrimaryKey
Message
 
To
10/08/2006 09:02:00
Jeff Corder
Ambit Technologies, LLC
Missouri, United States
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01144358
Message ID:
01144678
Views:
20
Thank you very much.
Regards
>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
Fred Besterwitch, MCP

The harder you work. The luckier you get.
Previous
Reply
Map
View

Click here to load this message in the networking platform