|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Form Validation
Hi,
I am new to ASP, I am working on a web site that uses ASP and MS Access for the guestbook section. The problem I am facing is with a form, to fill in visitor comments. Firstly there are some field in the form that are optional and can be left blank, but when these fields are left blank and the form is submitted, I get an error saying that the length of this optional field cannot be zero. Secondly I am having problems with inserting new rows into the database. The insert statement works fine at times and at other times gives an error saying it should be an updateable query. This is the query: sqlstring= "INSERT INTO comment (" &_ "ID , FirstName , LastName , Email , Country , City , Comments ) VALUES (" &_ userid & " , '" & F1 & "' , '" & F2 & "' , '" & F3 & "' , '" & F4 & "' , '" & F5 & "' , '" & F6 & "')" con.Execute sqlstring This was never working so I changed it to: con.Execute sqlstring,,adCmdText + adExecuteNoRecords This started working but now again it is not working and says that the query should be updateable. |
|
#2
|
|||
|
|||
|
The problem with the optional fields saying that they cannot be a zero length will be in the tables you created in Access. Go into design view for the table you're trying to insert the record into and check that Allow Zero Length on the optional fields is not set to No. If it is, then change it to yes.
Secondly your SQL statement has syntax errors in it....this is how it should be written. sqlString = "Insert into tblName(ID , FirstName , LastName , Email , Country , City , Comments)" _ & " Values ('" & F1 & "', '" & F2 & "', '" & F3 & "', '" & F4 & "', '" & F5 & "', '" & F6 & "')" I noticed that you had 7 fields you wanted to insert into, but only 6 values - which is how I've copied it. If your ID field in the database is an Autonumber field you don't need to inlude that in the fields list as it will auto-assign an id to each record for you. If it is *not* an autonumber field and you're making the ID up yourself then you need to add an extra value into the sql statement. use the following to execute the query set rs = con.execute(sqlstring) where rs is your recordset object variable. Hope this helps |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Form Validation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|