Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 28th, 2006, 03:09 PM
aozm aozm is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 1 aozm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 5 sec
Reputation Power: 0
Question Create new id

Hello,

I need help with the following:

Basically, what I am trying to do is generate a unique id when the user clicks a button on my web page. SSN's used to be used before, but those are no longer being required. I'm trying to find an SSN replacement - it must be 9 characters long. But, instead of all numbers, it will be 8 letters and then a number. I want to make sure the value that is generated is always unique.

How can I do this? Is this best done in the asp code or on the sql side? Thoughts?

Thanks!

Reply With Quote
  #2  
Old November 30th, 2006, 08:51 AM
degsy degsy is offline
Contributing User
ASP Free God 2nd Plane (6000 - 6499 posts)
 
Join Date: Aug 2005
Location: North East, UK
Posts: 6,191 degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 19 h 41 m 52 sec
Reputation Power: 122
Here is a script to generate a random string. 8 letters 1 number.

It also has a check to make sure a duplicate record is not inserted.

Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open Server.MapPath("RandomOrderNumber.mdb")
%>

<%
		
Function getRand()
Randomize

lowestNumber=0
highestNumber=9
MyOrderNum = Int((highestNumber - lowestNumber + 1) * Rnd + lowestNumber)

lowestLetter=65
highestLetter=90
For x=1 To 8 
	MyOrderLetter = MyOrderLetter & Chr(Int((highestLetter - lowestLetter + 1) * Rnd + lowestLetter)) 
Next

getRand = MyOrderLetter & MyOrderNum
End Function

Function InsertData(ordernum)
sql = "SELECT orderno FROM orders WHERE orderno = '" & ordernum & "'"
		'Response.Write sql
		set rs=Server.CreateObject("ADODB.recordset")
		rs.Open sql, conn
		If Not rs.EOF Then
			InsertData = False
			Response.Write "<span style=""color:red"">" & ordernum & ": " & "NOT ADDED</span><br>"
			rs.Close
		Else
			sql = "INSERT INTO orders (orderno) VALUES ('" & ordernum & "')"
			InsertData = True
			Response.Write ordernum & ": " & "ADDED<br>"
			conn.Execute sql
		End If
End Function
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<form name="form1" method="post" action="">
  <input name="Add" type="submit" id="Add" value="Add Records">
  <input name="Show" type="submit" id="Show" value="Show All Records">
  <input name="Clear" type="submit" id="Clear" value="Delete All Records">
  <input name="Test" type="submit" id="Test" value="Test">
  <input name="orderno" type="text" id="orderno" maxlength="10">
</form>

<%
If Len(Request.Form("Add")) > 0 Then
Count = 0
Called = 0
Do Until Count = 100
	tmp = InsertData(getRand)
	If tmp <> False Then
		Count = Count + 1
	End If
	Called = Called + 1
Loop
Response.Write "Called " & Called & " Times<br>"
Response.Write Count & " Records Added"
End If


If Len(Request.Form("Show")) > 0 Then
	set rs=Server.CreateObject("ADODB.recordset")
	sql = "SELECT id, orderno FROM orders"
	rs.Open sql, conn
	Response.Write "<table border=""1"" cellspacing=""0""><tr><td>Count</td><td>ID</td><td>OrderNo</td></tr>"
		Do While Not rs.EOF
			Count = Count + 1
			Response.Write "<tr><td>" & Count & "</td><td>" & rs("id") & "</td><td>" & rs("orderno") & "</td></tr>"
			rs.MoveNext
		Loop
	Response.Write "</table>"
	rs.Close
End If	



If Len(Request.Form("Test")) > 0 Then 
	If Request.Form("orderno") <> "" Then
		orderno = Request.Form("orderno")
	Else
		orderno = 0
	End If
	  
	set rs=Server.CreateObject("ADODB.recordset")
	sql = "SELECT id, orderno FROM orders WHERE orderno='" & orderno & "'"
	rs.Open sql, conn
	
	If Not rs.EOF Then
		Response.Write orderno & " Exists<br>"
	Else
		Response.Write orderno & " does not exist<br>"
	End If
End If

If Len(Request.Form("Clear")) > 0 Then
	set rs=Server.CreateObject("ADODB.recordset")
	sql = "DELETE FROM orders"
	rs.Open sql, conn
	Response.Write "Records Deleted"
End If
%>

</body>
</html>
<%
conn.Close
%>
__________________
CyberTechHelp

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Create new id


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek