CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 how to put guid into sql server UNIQUEIDENTIFIER

Print topic Send  topic

Author Message
jamesplank

Posts: 8
Posted: 06/27/2006, 1:54 AM

I can generate a GUID
and i can insert it into the datasource in the BeforeBuid Insert

and the sqlserver 2005 pK FIELD IS A UNIQUEIDENTIFIER

BUT I cant get the thing to stick?

using your framwork how do I convert (using ASP) the guid to gointo a unqueidentifier for sqlserver 2005

Im assuming the hidden field is type text?
i use this code:
MediaProduct1.DataSource.PK_MediaProduct.value = server.createobject("scriptlet.typelib").guid

i get this error message?
Unclosed quotation mark after the character string '{0456F322-AED4-4BAA-B24C-1A783963DF02}'. (Microsoft OLE DB Provider for SQL Server)

and ive tried this which I found on the web
'MediaProduct1.DataSource.PK_MediaProduct.value = mid(server.createobject("scriptlet.typelib").guid,1,38)

but i get this

String or binary data would be truncated. (Microsoft OLE DB Provider for SQL Server)

any ideas? To convert it to a acceptable form for a UNIQUEIDENTIFIER field?

Help
Thanks
_________________
James Nicholson-Plank
Icon Communications Ltd
New Zealand
ph 0064-3-3659899
View profile  Send private message
marcwolf


Posts: 361
Posted: 06/27/2006, 6:40 AM

Hi there..

Ok - we have done something similar except we strip out 'bad' characters the the single quotes and the '{}'

To get a safe GUI this is the call we use
  
sKey = CVS_createGuid(1)  
MediaProduct1.DataSource.PK_MediaProduct.value = sKey  

Here is the code that we use

  
'*****************************************************************   
'@desc 		Returns a GUID for global uniqiness  
'@param     0 Strip All, 1 Strip {}  
Function CVS_createGuid(StripAll)  
  Dim Typelib, tg   
  Set TypeLib = Server.CreateObject("Scriptlet.TypeLib")  
  tg = TypeLib.Guid  
  If StripAll = 1 then   
  	CVS_ReplaceAllByExpression  tg, "[^a-zA-Z0-9()]" ,""   
  else  
  	CVS_ReplaceAllByExpression  tg, "[^a-zA-Z0-9()]-" ,""  
  End If  
  CVS_createGuid = ucase(tg)  
  Set TypeLib = Nothing  
End Function  
  
  
'*****************************************************************   
'@desc 		RegExp Replacement  
'@param     StringToExtract - Passed and return string  
'@param     MatchPattern - What to look for  
'@param     ReplacementText - What to replace text with  
Sub CVS_ReplaceAllByExpression(ByRef StringToExtract, ByVal MatchPattern, ByVal ReplacementText)  
	Dim regEx, CurrentMatch, CurrentMatches  
  
	Set regEx = New RegExp  
	regEx.Pattern = MatchPattern  
	regEx.IgnoreCase = True  
	regEx.Global = True  
	regEx.MultiLine = True  
	StringToExtract = regEx.Replace(StringToExtract, ReplacementText)  
	Set regEx = Nothing  
  
End Sub  

Hope this helps

Dave


_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
View profile  Send private message
jamesplank

Posts: 8
Posted: 06/28/2006, 1:13 AM

Thanks for the prompt reply
I tried your answer and got...

"String or binary data would be truncated. (Microsoft OLE DB Provider for SQL Server)"

What is the field type "uniqueidentifier" ie a hex?
do i have to do some kind of convert first?
Im wondering if the sql server could have some settings that make this difficult?

Thanks for the try. Not sure what to try next?

Cheers
james:-/:-/:-/:-/
_________________
James Nicholson-Plank
Icon Communications Ltd
New Zealand
ph 0064-3-3659899
View profile  Send private message
marcwolf


Posts: 361
Posted: 06/28/2006, 6:30 PM

Hi James.


Sorry I don't know about thhis new fields type but I did do somne reading.

http://msdn.microsoft.com/library/default.asp?url=/libr..._ua-uz_6dyq.asp

It seems that it does use a GUI. But what I do in my routines is to remove the '-' as well..


So try this that does leave in the hyphens.

  
sKey = CVS_createGuid(0)    
MediaProduct1.DataSource.PK_MediaProduct.value = sKey   

However .. As the NEWID is a MSSQL function you might try this

  
aa = ccdlookup("NEWID", "" ,"", connection)  

A trick with the ccdlookup CCS function is that you can put a whole SQL statement in the first parameter and leave the others blank..

Take Care and hopes this helps

Dave

_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
View profile  Send private message
James Nicholson-Plank
Posted: 06/28/2006, 7:24 PM

Thanks Dave
Ill give it a go

Cheers james:-O
James Nicholson-Plank
Posted: 06/29/2006, 7:32 PM

Dave
I solved it.
Your code did work. A number of factors hidden on the database masked the true problem.

Regards James:-D
marcwolf


Posts: 361
Posted: 07/01/2006, 7:40 PM

Thanks James.
Now I know something more about MSSQL..

Helping others is often a learning process in it self :-)

Nice to see a fellow local too.. I'm Just west of you.. Brisbane Australia way.

Take Care

Dave
_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.