How to work with MSSQL uniqueidentifier type

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

Guest

I have a MSSQL table that has a uniqueidentifier that defaults to (newid())
I'm getting the following Error when I try to insert a new record into the dataset

Column 'ID' does not allow null

I've hacked at the properties for a while but no luck...any clues

TIA
Ro
 
You cant generate an UniqueIdentifier manually .. it is always generated by
the system..
for inserting user something like this... Consider 2 columns in your table,
one UniqueIdentifier and string ( varchar )...

I would insert like:::
insert into table1 values( newid(), 'some name' )

If you want it to bring it to front end and update or pass it to stored
procedures ... then store this UID as string varaible in programs
while sending it to dB send it as
new Guid( stringvariable );

will give you the uniqueidentifier required... for DB Operations,....
 
Sanjeeva said:
You cant generate an UniqueIdentifier manually .. it is always generated by
the system..

This is interesting.

So you mean the hundreds of thousands of database entries I have done here -
do not exist?

I am shocked.

Reality check:

* UniqueIdentifier maps to System.Guid.
* Guid.NewGuid () (static) can be used to get a new guid in the .NET world.
* This GUID can then be included into the insert statement more than easily
for anyone caring to try it out.

Sorry, your statement is as wrong as it can be.

--
Regards

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
(CTO PowerNodes Ltd.)
 
I meant the same thing. It is always generated by system

whether with NEWID() in SQL or
Guid.NewGuid() in C# its always generated ---- it cant
be whatever we assign the vaules like other datatypes....

--
Regards,
Sanjeeva
Proteans Software Solutions
 
Back
Top