|
 |
asp_databases thread: interrogating a Checkbox
Message #1 by Leo Clayton <claytonl@z...> on Thu, 19 Oct 2000 17:28:33 -0400
|
|
--=====================_108809019==_.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed
I have just created a FORM with CHECKBOXES from the following code:
<%
strSQL = "SELECT * FROM SkillsTable;"
Set DbObj = Server.CreateObject("ADODB.CONNECTION")
DbObj.Open "DSN=EmployeeMaster"
Set oRs = DbObj.Execute(strSQL)
%>
<FORM ACTION="CreateSkillsRecord2.asp" METHOD="POST" id=form1
name=SelectingSkills>
<TABLE BORDER=0>
<% Do WHILE NOT oRs.EOF
Response.Write("<tr>")
For i = 1 to 3
If not oRs.EOF Then
Response.Write(_
"<td><input type=Checkbox name=skill>" &_
"<td> " &
oRs.Fields("SkillName").Value & "</td>")
oRs.MoveNext
Else
Response.Write(_
"<td> </td>" &_
"<td> </td>")
End If
Next
Response.Write(_
"</tr>")
Loop
%>
</TABLE>
and it works!
Now I need to read this FORM to create a RECORD in a TABLE whenever there
is a check in the box.
I won't know in advance how many boxes will be checked.
The code that I am using to generate the table in the next page is the
following:
Dim NewSkill 'recordset object
Dim NewConnection 'Connection to database
' creating connection
Set NewConnection = Server.CreateObject("ADODB.Connection")
' create the recordset object
dsn="EmployeeMaster"
Set NewSkill = Server.CreateObject("ADODB.Recordset")
NewConnection.Mode=3
NewConnection.Open dsn
' opening the recordset object
'sql="select * FROM EmployeeSkillsTable"
NewSkill.Open "EmployeeSkillsTable",NewConnection, adOpenStatic,
adLockOptimistic
' adding the new record
If Request.Form("skill").Count > 0 Then
For skillcount = 1 to Request.Form("skill").Count
If Request.Form("skill") = "on" Then
'generating Skill ID key
LastName = Session("LastName")
IDNumber = Session("IDNumber")
s=Len(Lastname)
a=1
do while a<=s
Textchar = Mid(Lastname,a,1)
if Textchar = "'"then
Newname=Newname
else
Newname=Newname & Textchar
end if
a=a+1
loop
IDLeft4 = Newname
SkillID=Left(IDLeft4,4) & Date() & Time()
sqladd = "INSERT INTO EmployeeSkillsTable (SkillID, IDNumber)"
sqladd = sqladd &" VALUES('"&SkillID&"','"&IDNumber&"')"
Set NewSkill = NewConnection.Execute(sqladd)
End If
next
End If
%>
<%
' now close and clean up
NewSkill.Close
Set NewSkill = Nothing
NewConnection.Close
Set NewConnection = Nothing
%>
But it doesn't work. No records are being created.
What I thought I was doing was counting the number of boxes and if the box
was checked, creating a record in a table that had two (2) columns in it.
I'm STUCK!!
Message #2 by "Ken Schaefer" <ken@a...> on Sat, 21 Oct 2000 23:34:05 +1000
|
|
Change:
> Set NewSkill = NewConnection.Execute(sqladd)
to just:
NewConnection.Execute(sqladd)
You don't need do the Set NewSkill = bit
Next, just after:
> sqladd = "INSERT INTO EmployeeSkillsTable (SkillID, IDNumber)"
> sqladd = sqladd &" VALUES('"&SkillID&"','"&IDNumber&"')"
Do this:
Response.Write(sqladd & "<br>")
and this will show what you're trying to send to the database...
Cheers
Ken
----- Original Message -----
From: "Leo Clayton" <claytonl@z...>
To: "ASP Databases" <asp_databases@p...>
Sent: Friday, October 20, 2000 7:28 AM
Subject: [asp_databases] interrogating a Checkbox
> I have just created a FORM with CHECKBOXES from the following code:
> <%
> strSQL = "SELECT * FROM SkillsTable;"
> Set DbObj = Server.CreateObject("ADODB.CONNECTION")
> DbObj.Open "DSN=EmployeeMaster"
> Set oRs = DbObj.Execute(strSQL)
> %>
>
> <FORM ACTION="CreateSkillsRecord2.asp" METHOD="POST" id=form1
> name=SelectingSkills>
> <TABLE BORDER=0>
>
> <% Do WHILE NOT oRs.EOF
> Response.Write("<tr>")
> For i = 1 to 3
> If not oRs.EOF Then
> Response.Write(_
> "<td><input type=Checkbox name=skill>" &_
> "<td> " &
> oRs.Fields("SkillName").Value & "</td>")
> oRs.MoveNext
> Else
> Response.Write(_
> "<td> </td>" &_
> "<td> </td>")
> End If
> Next
>
> Response.Write(_
> "</tr>")
> Loop
> %>
> </TABLE>
> and it works!
>
> Now I need to read this FORM to create a RECORD in a TABLE whenever there
> is a check in the box.
>
> I won't know in advance how many boxes will be checked.
>
> The code that I am using to generate the table in the next page is the
> following:
> Dim NewSkill 'recordset object
> Dim NewConnection 'Connection to database
>
> ' creating connection
> Set NewConnection = Server.CreateObject("ADODB.Connection")
>
> ' create the recordset object
> dsn="EmployeeMaster"
> Set NewSkill = Server.CreateObject("ADODB.Recordset")
> NewConnection.Mode=3
> NewConnection.Open dsn
>
> ' opening the recordset object
> 'sql="select * FROM EmployeeSkillsTable"
> NewSkill.Open "EmployeeSkillsTable",NewConnection, adOpenStatic,
> adLockOptimistic
>
> ' adding the new record
> If Request.Form("skill").Count > 0 Then
> For skillcount = 1 to Request.Form("skill").Count
> If Request.Form("skill") = "on" Then
> 'generating Skill ID key
> LastName = Session("LastName")
> IDNumber = Session("IDNumber")
>
> s=Len(Lastname)
> a=1
> do while a<=s
> Textchar = Mid(Lastname,a,1)
> if Textchar = "'"then
> Newname=Newname
> else
> Newname=Newname & Textchar
> end if
> a=a+1
> loop
> IDLeft4 = Newname
>
> SkillID=Left(IDLeft4,4) & Date() & Time()
>
> sqladd = "INSERT INTO EmployeeSkillsTable (SkillID,
IDNumber)"
> sqladd = sqladd &" VALUES('"&SkillID&"','"&IDNumber&"')"
> Set NewSkill = NewConnection.Execute(sqladd)
> End If
> next
> End If
>
> %>
>
>
> <%
>
> ' now close and clean up
> NewSkill.Close
> Set NewSkill = Nothing
> NewConnection.Close
> Set NewConnection = Nothing
>
> %>
>
> But it doesn't work. No records are being created.
> What I thought I was doing was counting the number of boxes and if the box
> was checked, creating a record in a table that had two (2) columns in it.
> I'm STUCK!!
>
|
|
 |