Solved

NEWID() in c#

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now