Creating a GUID???

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

I need to generate a unique number/string of some description and thought a
guid would be ideal.
Any ideas on how to generate a guid?

I'm not using SQL server so SELECT NEWID() is out but something similar in
code would be great.

I've looked at the System.Guid class but can't figure how to have it
generate a fresh GUID.

Thanks for any pointers.
 
I guess you have to call the static method Guid.NewGuid(). This will return
you a new instance. Then, if you need to extract the generated value, call
either the ToString() or ToByteArray() method.

- José
 
Okay Steve, I am a newbie but I think this might help.

I am taking this from some code I wrote that inserts a guid into a database,
but doesn't use a SELECT satement to create it.

I am going to include the code before, to give it context. Here goes:
string sql = @"
INSERT INTO [TableName]
(UserID, Name)
VALUES
('{0}','{1}')";

values.Add(Guid.NewGuid().ToString()); //this is code you want
value.Add(txtName.Text); //this referes to a text box on a webform

please let me know if that helps, apologies if I only confused the issue.

best
 
I'm not using any, Its a file based app which creates template files that
needed some unique ID mainly for internal purposes.
 
Back
Top