RE: GUIDs & uniqueidentifiers in datasets

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Cowboy (Gregory A. Beamer) - MVP (NoSpamMgbworld_at_comcast.netNoSpamM)
Date: 11/08/04


Date: Mon, 8 Nov 2004 09:30:02 -0800

You can generate a new GUID in your code using the System.Guid structure.
This GUID will still be globally unique, even though it is not created in the
database.

---
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"James Coates" wrote:
> I am developing a windows forms application which takes its data from an SQL 
> server database where all the primary keys are uniqueidentifier fields.
> 
> I am creating strongly typed datasets and populating them using the Fill 
> method. My problem is how to generate guids when inserting rows into the 
> datasets, for example when the dataset is bound to a datagrid control. Can 
> this be done?
> 
> I have also tried using the AddRow method as below:
> 
> Dim drNewRow As DsProductRange.CategoriesRow = 
> dsProductRange1.Categories.NewCategoriesRow
> 
> drNewRow.CategoryID.NewGuid()
> drNewRow.CategoryName = "New Range"
> dsProductRange1.Categories.AddCategoriesRow(drNewRow)
> 
> However the .NewGuid() method here doesn't seem to work as the CategoryID 
> field has already picked up a {System.InvalidCastException} error (I think 
> related to the way the field is described in the generate XSD schema. Is 
> there anyway to generate guid values as default values to the dataset field 
> like calling the newid() function in the SQL table?
> -- 
> James Coates
> York, England


Relevant Pages

  • RE: GUIDs & uniqueidentifiers in datasets
    ... > This GUID will still be globally unique, even though it is not created in the ... >> I am developing a windows forms application which takes its data from an SQL ... >> server database where all the primary keys are uniqueidentifier fields. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Using GUID as primary key in DB
    ... GUIDs are supposed to be globally unique. ... Although it is theoretically possible to get a duplicate, ... It should not matter where the GUID was generated. ... I used .NET to generate a GUID for creating a new record in Access DB as primary key. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How do you generate a GUID in java?
    ... Erico Di Gelato wrote: ... I don't build GUID exists. ... UID does. ... But that's not globally unique. ...
    (comp.lang.java.help)
  • Re: programatically add table in access
    ... In SQL Server you can default a guid datatype with a newGUIDbuiltin function, but check the documentation for Access. ... Autonumber is a field attribute, as is the format property which you would use to set the displayed decimal places. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Setting control value based on a SQL Select statement
    ... I don't understand what you mean by « So as an alternative I use a SQL ... Select statement where GUID = linked server GUID in the hope I can return ... The form is bound to a SQL view and the control is bound to a field ... Each time you select a client from the client combo box a GUID is ...
    (microsoft.public.access.adp.sqlserver)