Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 11th, 2005, 10:32 AM
Authorized User
 
Join Date: Feb 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default create a unique id in asp code

Im tyring to create a unique member id in code, and update the member table with member details. I get the following error:

Microsoft JET Database Engine error '80040e21'

Index or primary key cannot contain a Null value.

/Project/AddUser.asp, line 39

Could anyone please advise me on how to fix this error? thanks.

*--------------------------------------------------------------------


<%
  Dim rsUsers, strUserId
  Set rsUsers = Server.CreateObject("ADODB.Recordset")
  rsUsers.Open "Members", objConn, adOpenForwardOnly,adCmdTable
  if session("MemberId") <> "" then
    rsUsers.filter = "MemberId = '" & session("MemberId") & "'"
  else
    rsUsers.filter = "EmailAddress = '" & request. form("txtEmailAddress") & "'" &_
             "AND Password = '" & request.form("pwdPassword") & "'"
  end if

  rsUsers.AddNew
  strUserId = rsUsers("MemberId")
  strUserId = strUserId + 1
  rsUsers("MemberId") = strUserId

  rsUsers("TraderName") = request.form("txtTraderName")
  rsUsers("Password") = request.form("pwdPassword")
  rsUsers("Firstname") = request.form("txtFirstname")
  rsUsers("Surname") = request.form("txtSurname")
  rsUsers("EmailAddress") = request.form("txtEmailAddress")
  rsUsers("MobileNumber") = request.form("txtMobileNumber1")
  if Request.form("chkEmailUpdates") = "on" then
    rsUsers("EmailUpdates") = true
  else
    rsUsers("EmailUpdates") = false
  end if
  if request.form("chkSmsUpdates") = "on" then
    rsUsers("SmsUpdates") = true
  else
    rsUsers("SmsUpdates") = false
  end if
  rsUsers("CashBalance") = 100000
  rsUsers("PortfolioValue") = 100000
  rsUsers("Active") = true

  rsUsers.update

  Dim strName, strValue
  for each strField in rsUsers.fields
    strName = strField.Name
    strValue = strField.Value
    session(strName) = strValue
  next
  Session("blnValidUser") = True
  response.redirect "MyPortfolio.html"
%>

 
Old March 15th, 2005, 03:55 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

following are possible solutions:
1. You can use auto number of MS-Access, which will create autonumber itself.

2. I think u should remove the condition to get the auto number.

  rsUsers.AddNew
  strUserId = rsUsers("MemberId")
  strUserId = strUserId + 1
  rsUsers("MemberId") = strUserId

 What is happening is it gets no record if there is no match (with filter), and so why the error.



Om Prakash





Similar Threads
Thread Thread Starter Forum Replies Last Post
generate unique id capri SQL Server 2000 1 April 6th, 2008 10:18 AM
ASP with MS Access unique ID AA00 -> ZZ99 sv3n1980 Access ASP 0 May 9th, 2007 08:11 AM
SQL script to create a unique ID for records chubnut SQL Server 2000 1 October 16th, 2006 07:25 AM
Create Unique Id langer123 Classic ASP Basics 0 April 6th, 2005 01:27 PM
Getting Unique ID from Database Nicky_uk Classic ASP Databases 9 January 26th, 2005 04:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.