DataColumn expression to create new Guid

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

Guest

I would like to set up a DataColumn in my table of type Guid and a new
Guid(Guid.NewGuid) would be the expression that gets evaluated when ever a
new row was added. I have the DataSet bound to a grid so I would like to set
this up at compile time. The Guid DataColumn is also the primary key so it
has to be set when a row is added.

Thanks,
Marc
 
Hi Marc,

You might use DataTable.RowChanged event?
Use this code, for example:
if (e.Action == DataRowAction.Add)
e.Row["Guid"] = Guid.NewGuid();
 
Thanks,

Marc

Miha Markic said:
Hi Marc,

You might use DataTable.RowChanged event?
Use this code, for example:
if (e.Action == DataRowAction.Add)
e.Row["Guid"] = Guid.NewGuid();

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Marc said:
I would like to set up a DataColumn in my table of type Guid and a new
Guid(Guid.NewGuid) would be the expression that gets evaluated when ever a
new row was added. I have the DataSet bound to a grid so I would like to
set
this up at compile time. The Guid DataColumn is also the primary key so
it
has to be set when a row is added.

Thanks,
Marc
 
Back
Top