Solved

NEWID() in c#

Posted on 2010-09-15
5
3,083 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

821 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