Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP! Getting error in inserting into a Access database

Status
Not open for further replies.

mlm823

Programmer
Oct 29, 2003
39
US
Okay I'm new to ASP...use to doing PHP but my client has an asp only server.... I've create an Access 97 db called CTCLCDb.mdb and I'm working with a table called Users.

I'm trying to insert information into the table

Here is the code - I have it in a Procedure
Sub AddingUser

'Declare Variables for form data and asssign values
Dim strName, strLogin, strPassword, strType
strName = Request.Form("Name")
strLogin = Request.Form("Login")
strPassword = Request.Form("Password")
strType = Request.Form("Type")
Response.Write "Login entered "
Response.Write strLogin
Response.Write " Password Entered "
Response.Write strPassword
Response.Write " Type selected "
Response.Write strType

'Take the password and encrypt it with the global key and function defined in header

Response.Write &quot; <BR> The encryption key &quot;
Response.Write strEncryptKey
Dim varEncryptedPassword, varDecryptedPassword
varEncryptedPassword = EncodeKey(strPassword,strEncryptKey)
Response.Write &quot;<BR> the encrypted password is &quot;
Response.Write varEncryptedPassword
varDecryptedPassword = DecodeKey(varEncryptedPassword,strEncryptKey)
Response.Write &quot;<BR> the decrypted password is &quot;
Response.Write varDecryptedPassword

'Take the variables and insert them into the users table
'Create an ADO connection object
Set adoCon = Server.CreateObject(&quot;ADODB.Connection&quot;)


'Set an active connection to the Connection object using a DSN-less connection
strConnectionString=&quot;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=&quot; &

Server.MapPath(&quot;../database/CTCLCDb.mdb&quot;)
adoCon.Open strConnectionString

'SQL String
strSQL = &quot;INSERT INTO Users(Name,LoginName,Password,Type)&quot; & _ &quot; VALUES('&quot; & strName &

&quot;' , '&quot;& _ strLogin &&quot;', '&quot; &_ varEncryptedPassword & &quot;', '&quot; &_ strType & &quot;')&quot;

'Execute SQL
adoCon.Execute strSQL

'Close connections
adoCon.Close
set adoCon = Nothing

'Statement saying user has been added
Response.Write &quot;<p> <STRONG>User &quot;
Response.Write strName
Response.Write &quot; has been added to the table. </STRONG></p>&quot;
End Sub

Here is the error I'm getting
Microsoft VBScript compilation error '800a0408'

Invalid character

/4Final/CTAdminTool/usersDetail.asp, line 48

strSQL = &quot;INSERT INTO Users(Name,LoginName,Password,Type)&quot; & _ &quot; VALUES('&quot; & strName & &quot;' , '&quot;& _ strLogin &&quot;', '&quot; &_ varEncryptedPassword & &quot;', '&quot; &_ strType & &quot;')&quot;
---------------------------------------------------------------^

The ^ is pointing under the V in VALUES

Here is the website if you want to see the error better

Any help is most appreciated... I'm going crazy trying to figure this mess out.

Happy New Years!
Maranda
 
OKay I've gotten the error to go away... changed the statement to be like

strSQL = &quot;INSERT INTO Users(Name,LoginName,Password,Type)&quot; & _
&quot; VALUES('&quot; & strName & &quot;' , '&quot;& strLogin &&quot;', '&quot; & varEncryptedPassword & &quot;', '&quot; & strType

& &quot;')&quot;

Now get this error

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Microsoft Access Driver] Operation must use an updateable query.

/4Final/CTAdminTool/usersDetail.asp, line 52

Does anyone know why I'm getting this?

Maranda
 
Check the permissions on the server or folder if it is set to read only it can return that error. Not necessarily anything wrong with your code.
 
Hi Maranda,

Instead of using an Execute try opening a recordset and then using...

Code:
<%
strsql = &quot;SELECT * FROM [Users] WHERE 0 = 1&quot;
Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs.Open strsql, adoCon, 1, 2
rs.AddNew

rs(&quot;Name&quot;) = Request.Form(&quot;Name&quot;)
rs(&quot;LoginName&quot;) = Request.Form(&quot;Login&quot;)
strPassword = Request.Form(&quot;Password&quot;)
varEncryptedPassword = EncodeKey(strPassword,strEncryptKey)
rs(&quot;Password&quot;) = varEncryptedPassword
rs(&quot;Type&quot;) = Request.Form(&quot;Type&quot;)
rs.Update
rs.Close
%>
Now, even though the Recordset is closed you still have the Request.Form elements to display the information and you have the varEncryptedPassword variable which you can use to show the encrypted password.

============================================================

LogicaLunatic
 
Sorry,

Also, doing it the way I suggested above will keep you from getting SQL errors if a person's name is say...

Graham O'Neil

which would throw off your Query because of the &quot; ' &quot; character.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top