Solved

NEWID() in c#

Posted on 2010-09-15
5
3,106 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 500 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

830 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