Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

NEWID() in c#

Posted on 2010-09-15
5
Medium Priority
?
3,388 Views
Last Modified: 2012-06-21
hi experts, i have this code in transact sql
SELECT @AutoGenerado = cast(@CodigoActividadesDiscentes as varchar(max)) +
                                   cast(substring(cast(abs(cast(cast(NEWID() as varbinary) as bigint)) as varchar(20)), 1, 10) as varchar(max));

I need a function similar or equal. net (c #), please
0
Comment
Question by:enrique_aeo
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 33684462
Well, to get a new guid you would use:

string newId = Guid.NewGuid().ToString();

Open in new window

0
 

Author Comment

by:enrique_aeo
ID: 33685768
but the code in sql server there is more code, which is sufficient to indicate?
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 33686105
Well, where does the value in @CodigoActividadesDiscentes come from?
0
 

Author Comment

by:enrique_aeo
ID: 33686192
is the primary key and an identity
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 33686554
In that case you can't directly translate the code you posted to C#. You need code to access the database, retrieve the value of the key field based on some criteria, and then do the whole parsing/string concatenation in code.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question