How do I set the default value to a new GIUD

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

Guest

I am using the IDE to create dataset, datatable, and configure the columns.
What I need to know now is how do I configure in the IDE the default value so
that it creates a new GUID.

I have set the column type to a GUID, and i can see where it says the
default value (Currently set to <dbNull>) and I want to configure this to be
a new GUID. What do I set this value to...
 
You'd have to create a dataview that shows all rows of the table. One of the
events on the dataview is OnViewChanged ( I think that's but .. but anyway
it's the event that gets called everytime the datatable contents change) ..
and in that you'd have to fill in the GUID.

ADO.NET 2.0 has a new event called TableNewRow on DataTables that u could
use for the same purpose.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 
Actually scratch my previous reply, there's a much easier way - here's some
C# --
DataTable dt = new DataTable("DatesTable");
DataColumn dc = new DataColumn("myGuid") ;
dc.DataType = typeof(Guid) ;
dc.DefaultValue = Guid.NewGuid() ;
dt.Columns.Add(dc);
DataRow dr = dt.NewRow();
dt.Rows.Add(dr);
dr = dt.NewRow();
dt.Rows.Add(dr);

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 
GUIDs (Globally Unique IDs) can be generated by creating a GUID structure

//C#
Guid g = Guid.NewGuid();

//VB.NET
Dim g As Guid = Guid.NewGuid

It does not matter, with a GUID, how it is created, as there is no chance
the database will generate the same GUID you created for a row inserted
differently (okay, there is a "chance", but it is extremely remote; for all
practical purposes, it is not going to happen).

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Back
Top