DataColumn expression to create new Guid

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
 
M

Miha Markic [MVP C#]

Hi Marc,

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

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top