Tema: C#, MSSQL uniqueidentifier
Autorius: a
Data: 2010-11-15 09:27:27
Sveiki,

Pradedanciojo klausimas: turiu MSSQL lenta, sukuriu jai nauja Data Source'a 
VS2008. Draginu EventDetails lenta i forma. Designer'is sukuria kodo, kuris 
veikia. Dabar noriu, kad sukurtam DataGridView'e ivedus nauja eilute 
automatiskai EventID laukui butu iskvieciama SQL'o sistemine funkcija 
newid(), kurios rezultatu tas laukas butu uzpildomas.

Kaip tai paprasciau padaryti? Galima butu kazkaip pakeisti designer'io 
sukurta koda, kad veiktu pagal norus, ar logiskiau butu rasyti SQL atskirus 
uzklausos sakinius? Bet atrodytu, kad tai neturetu buti reikalinga - 
framework'e yra irankiai.

Pastinu info apie lentele is SQL Management Studio:

CREATE TABLE [dbo].[EventDetails](
    [DateOfOccurence] [datetime] NOT NULL,
    [CategoryID] [int] NOT NULL,
    [Type] [nvarchar](50) NOT NULL,
    [Value] [nvarchar](50) NULL,
    [Unit] [nvarchar](50) NULL,
    [Comment] [nvarchar](max) NULL,
    [EventID] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_EventDetails] PRIMARY KEY CLUSTERED
(
    [EventID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = 
OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

ALTER TABLE [dbo].[EventDetails] ADD  CONSTRAINT [DF_EventDetails_EventID] 
DEFAULT (newid()) FOR [EventID]