Connecting Tech Pros Worldwide Forums | Help | Site Map

Creating a GUID???

Steve
Guest
 
Posts: n/a
#1: Nov 16 '05
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.




Scott Allen
Guest
 
Posts: n/a
#2: Nov 16 '05

re: Creating a GUID???


You can use the static NewGuid method on the Guid struct.

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/
[color=blue]
> 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.
>[/color]


José Joye
Guest
 
Posts: n/a
#3: Nov 16 '05

re: Creating a GUID???


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é

"Steve" <steve_turton@lineone.net> a écrit dans le message de news:
u5zCXjQ8EHA.2276@TK2MSFTNGP09.phx.gbl...[color=blue]
>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.
>
>
>[/color]


ramonred
Guest
 
Posts: n/a
#4: Nov 16 '05

re: Creating a GUID???


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

"Steve" wrote:
[color=blue]
> 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.
>
>
>
>[/color]
Steve
Guest
 
Posts: n/a
#5: Nov 16 '05

re: Creating a GUID???


Thanks everyone, Guid.NewGuid() works a treat.

"Steve" <steve_turton@lineone.net> wrote in message
news:u5zCXjQ8EHA.2276@TK2MSFTNGP09.phx.gbl...[color=blue]
> I need to generate a unique number/string of some description and thought[/color]
a[color=blue]
> 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.
>
>
>[/color]


Sahil Malik
Guest
 
Posts: n/a
#6: Nov 16 '05

re: Creating a GUID???


What db are you using?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


"Steve" <steve_turton@lineone.net> wrote in message
news:e%23s2DVR8EHA.1400@TK2MSFTNGP11.phx.gbl...[color=blue]
> Thanks everyone, Guid.NewGuid() works a treat.
>
> "Steve" <steve_turton@lineone.net> wrote in message
> news:u5zCXjQ8EHA.2276@TK2MSFTNGP09.phx.gbl...[color=green]
>> I need to generate a unique number/string of some description and thought[/color]
> a[color=green]
>> 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.
>>
>>
>>[/color]
>
>[/color]


Steve
Guest
 
Posts: n/a
#7: Nov 16 '05

re: Creating a GUID???


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

"Sahil Malik" <contactmethrumyblog@nospam.com> wrote in message
news:uet6AmR8EHA.3260@TK2MSFTNGP14.phx.gbl...[color=blue]
> What db are you using?
>
> - Sahil Malik
> http://dotnetjunkies.com/weblog/sahilmalik
>
>
> "Steve" <steve_turton@lineone.net> wrote in message
> news:e%23s2DVR8EHA.1400@TK2MSFTNGP11.phx.gbl...[color=green]
> > Thanks everyone, Guid.NewGuid() works a treat.
> >
> > "Steve" <steve_turton@lineone.net> wrote in message
> > news:u5zCXjQ8EHA.2276@TK2MSFTNGP09.phx.gbl...[color=darkred]
> >> I need to generate a unique number/string of some description and[/color][/color][/color]
thought[color=blue][color=green]
> > a[color=darkred]
> >> 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.
> >>
> >>
> >>[/color]
> >
> >[/color]
>
>[/color]


Sahil Malik
Guest
 
Posts: n/a
#8: Nov 16 '05

re: Creating a GUID???


Okay then it's all cool.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


"Steve" <steve_turton@lineone.net> wrote in message
news:OSxysoX8EHA.2016@TK2MSFTNGP15.phx.gbl...[color=blue]
> I'm not using any, Its a file based app which creates template files that
> needed some unique ID mainly for internal purposes.
>
> "Sahil Malik" <contactmethrumyblog@nospam.com> wrote in message
> news:uet6AmR8EHA.3260@TK2MSFTNGP14.phx.gbl...[color=green]
>> What db are you using?
>>
>> - Sahil Malik
>> http://dotnetjunkies.com/weblog/sahilmalik
>>
>>
>> "Steve" <steve_turton@lineone.net> wrote in message
>> news:e%23s2DVR8EHA.1400@TK2MSFTNGP11.phx.gbl...[color=darkred]
>> > Thanks everyone, Guid.NewGuid() works a treat.
>> >
>> > "Steve" <steve_turton@lineone.net> wrote in message
>> > news:u5zCXjQ8EHA.2276@TK2MSFTNGP09.phx.gbl...
>> >> I need to generate a unique number/string of some description and[/color][/color]
> thought[color=green][color=darkred]
>> > 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.
>> >>
>> >>
>> >>
>> >
>> >[/color]
>>
>>[/color]
>
>[/color]


Closed Thread


Similar C# / C Sharp bytes