Hi,
Wondered if you can help resolve an error I'm having with my code written in asp.net1.1, vb2003 using an access database ? The error I receive is as follows :
Server Error in '/' Application.
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.
This error occurs intermittently within an e-commerce website when you click on the shop page to display a list of items for sale, which in turns create a cart. The pertinent code is shown below :
Code:
Function RandomNo()
If Session("CartID") Is Nothing Then
'Create random number
Dim RandomNumber As Integer
RandomNumber = int((1+99990 - 10001) * rnd) + 10001
'Display random number - testing only
lblRandom.Text += CStr("Value is:" & RandomNumber)
lblRandom.visible=False
'Create date parameter
Dim dateNow as Date = Date.Now
Dim dtcart = dateNow.ToString("dd/MM/yyyy")
'Remove brackets from date
Dim datenum = (Replace(dtcart,"/",""))
'Response.Write("datenum")
'Set session equal to random number and date
Session("CartID") = RandomNumber & datenum
'Response.Write(Session("CartID"))
'Call Createcart Function
createCart()
End If
End Function
and....
Function createCart()
'Define cart
objDT = New System.Data.DataTable("Cart")
'Set date and time
Dim dtNow as DateTime = DateTime.Now
Dim ts as String
ts = dtNow.ToString("dd/MM/yyyy" & " " & "HH:mm:ss")
'Updates Cart table in db
UpdatetblCart(Session("CartID"),ts)
End Function
Basically the first function creates a random number using 5 digits and then links this value with a date and time variable. I've tried increasing the random number from say 5 to 7 digits but no effect.
Also when this error appears in the browser window, if you click on refresh enough times, the error message disappears and the items are listed.
Any ideas - thanks ?