Solved

NEWID() in c#

Posted on 2010-09-15
5
3,217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

636 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