Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How generate a valid GUID
Message
De
06/09/2005 07:06:46
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
06/09/2005 05:41:08
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP1
Network:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
01046923
Message ID:
01046937
Vues:
64
This message has been marked as the solution to the initial question of the thread.
>Thank you Metin I will try
>
>Luigi

As an addition to what Metin said, you could as well get the GUID just as 16 bytes (a Guid is a 16bytes value) and use Guid constructor with byte[] (provided you don't do any codepage conversion).

ie:
* VFP code
Create table ("c:\temp\GUIDS") (GUID c(16) nocptrans)
For ix = 1 to 10
  Insert into ("c:\temp\GUIDS") values (GetGuid128bits())
endfor
Select GUID, GUID16ToStr(GUID) from ("c:\temp\GUIDS") into cursor crsDecoded
Copy To c:\temp\decoded.txt type delimited
Close Databases all
modi comm c:\temp\decoded.txt

Function GetGuid128bits
Declare Integer UuidCreate In 'RPCRT4.dll' String @pguid
Local pguid
pguid=Replicate(Chr(0),16)
UuidCreate(@pguid)
Return pguid

Function GUID16ToStr
Lparameters tcGUID
Declare Integer StringFromGUID2 In 'Ole32.dll' ;
	string rguid, String @lpsz, Integer cchMax
Local rGUID
rGUID=Replicate(Chr(0),80)
StringFromGUID2(m.tcGUID,@rGUID,40)
return Strconv(Left(rGUID,76),6)
EndFunc


*C# code
using System;
using System.Text;
using System.Data;
using System.Data.OleDb;

class GuidTest
{
 public static void Main()
 {
   string strCon = @"Provider=VFPOLEDB;Data Source=c:\temp\";
   string strSQL = @"select * from 'c:\temp\GUIDS'";
   OleDbConnection cn = new OleDbConnection(strCon);
   cn.Open();
   OleDbCommand cmd = new OleDbCommand(strSQL,cn);
   OleDbDataReader rdr = cmd.ExecuteReader();
   while (rdr.Read())
   {
      Guid myGuid = new Guid((byte[])rdr["GUID"]);
      Console.WriteLine( myGuid.ToString("B") );
   }
   rdr.Close();
   cn.Close();
 }
}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform