all groups > dotnet windows forms databinding > october 2006 >
You're in the

dotnet windows forms databinding

group:

Default value of a GUID field?!



Default value of a GUID field?! Leon_Amirreza
10/26/2006 12:00:00 AM
dotnet windows forms databinding: I have a column named "ID" and its type is "uniqueidentifier" in SQL Server
2005 Express.
this column is the primary key and its default value is "newid()" in SQL
Server.

I have generated a DataSet in C# that has this column but its default value
is DBNull what can I do to make the default value be the return value of
this function ( or I want the Id be generated by default in the DataSet)?

System.Guid.NewGuid()

Re: Default value of a GUID field?! Bart Mermuys
10/26/2006 8:45:37 PM
Hi,

[quoted text, click to view]

If you are using VB/VC#2005 then attach an eventhandler to
DataTable.TableNewRow to set a Guid.NewGuid.

HTH,
Greetings

[quoted text, click to view]

Re: Default value of a GUID field?! Leon_Amirreza
10/29/2006 12:00:00 AM
I have attached this handler but when the user goes to the last (empty) row
of the grid and then leaves this fake data row an error is reported and
DataGrid does detect that the user hasnt entered any value and the row
should be dissmissed!?

how to correct this problem?

[quoted text, click to view]

Re: Default value of a GUID field?! Bart Mermuys
10/29/2006 12:00:00 AM
Hi,

[quoted text, click to view]

How did you implement the handler ?

[quoted text, click to view]

If the user enters the empty row and then leaves without entering any data
then the row should be dismissed and attaching an eventhandler to
TableNewRow for setting a new guid doesn't seem to prevent this.

And are you using a DataGrid or DataGridView ?

HTH,
greetings

[quoted text, click to view]

Re: Default value of a GUID field?! Bart Mermuys
10/30/2006 5:01:52 PM
Hi,

[quoted text, click to view]

Looks ok to me, you're saying that this code is causing the problems with
the DGV ?

Greetings


[quoted text, click to view]

Re: Default value of a GUID field?! Leon_Amirreza
10/31/2006 12:00:00 AM
the function implementation is this:

void TableGroups_TableNewRow(object sender, DataTableNewRowEventArgs e)

{

(e.Row as DataSetGroups.TableGroupsRow).ID = Guid.NewGuid();

}

[quoted text, click to view]

AddThis Social Bookmark Button