|
 |
asp_cdo thread: Insert Data into a table
Message #1 by "Savonnya D. Rodrigues" <srod@f...> on Tue, 10 Apr 2001 11:16:47 -0700
|
|
I have generated a checkbox table by pulling all the values from the
database.
Example:
Set objRScbx =3D Server.CreateObject("ADODB.Recordset")
objRScbx.Open "Select Name from TableName ","DSN=3DMyDSN"
%>
<table border=3D"1" cellpadding=3D"2" cellspacing=3D"0">
<tr><td><table cellpadding=3D"2" cellspacing=3D"0" border=3D"0">
<table bgcolor=3D"#cccccc" cellspacing=3D"0" cellpadding=3D"2"
border=3D"0">
<%
Do While Not objRScbx.EOF
%>
<tr valign=3D"top" >
<td align=3D"right" width=3D"163"> <% =3DobjRScbx("Name") %> </td>
<td width=3D"150"><input type=3Dcheckbox name=3Dtxt<%
=3DobjRScbx("Name") %> size=3D20 ></td>
<td bgcolor=3D#cccccc colspan=3D6> </td>
<% objRScbx.MoveNext %>
<% If Not objRScbx.EOF then %>
<td align=3D"right" width=3D"163"><% =3DobjRScbx("Name") %></td>
<td width=3D"150"><input type=3Dcheckbox name=3Dtxt<%
=3DobjRScbx("Name") %> size=3D20 ></td>
<td bgcolor=3D#cccccc colspan=3D6> </td>
</tr>
<% objRScbx.MoveNext
end if
Loop
I want to insert the values that are checked into another table. The
problem is when I try to insert it want.
Example of the what I used to insert:
Set Dconn =3D Server.CreateObject("ADODB.Connection")
Dconn.Open "DSN=3DMyDSN"
SQL =3D "Select Name from TableName"
Set RecordSet =3D Dconn.Execute (SQL)
If Request.Form("txtChange") =3D "checked" then
'Insert data into the table
SQL_Mod=3D"Insert into Table (Num, Name) values ('" &
Request.Form(txtNum) & "','" & Request.Form(txtName) & "')"
ElseIf Request.Form("txtChange") =3D "unchecked" then
'Delete data from table
SQL_Mod=3D"Delete Name from Table where Num =3D '" &
Request.Form("txtNum") &"'"
Dconn.Execute (SQL_Mon)
End If
Dconn.Close
Set Dconn =3D Nothing
%>
Can some one help!!!
Message #2 by ulateef@a... on Wed, 11 Apr 2001 11:58:48 +0500
|
|
Savonnya,
By looking at ur code the first part of code seems totally different from
the other part. The checkboxes name defined in first part of code are not
matching in the second part where Request.Form is used. You are
concatinating a DB field with checkbox name i.e, name=txt<%=objRScbx
("Name"). Plz make sure the name of form items defined are same where u r
fetching it.
Umair Latif
ASP_CDO Digest for Tuesday, April 10, 2001.
1. Insert Data into a table
----------------------------------------------------------------------
Subject: Insert Data into a table
From: "Savonnya D. Rodrigues" <srod@f...>
Date: Tue, 10 Apr 2001 11:16:47 -0700
X-Message-Number: 1
I have generated a checkbox table by pulling all the values from the
database.
Example:
Set objRScbx =3D Server.CreateObject("ADODB.Recordset")
objRScbx.Open "Select Name from TableName ","DSN=3DMyDSN"
%>
<table border=3D"1" cellpadding=3D"2" cellspacing=3D"0">
<tr><td><table cellpadding=3D"2" cellspacing=3D"0" border=3D"0">
<table bgcolor=3D"#cccccc" cellspacing=3D"0" cellpadding=3D"2"
border=3D"0">
<%
Do While Not objRScbx.EOF
%>
<tr valign=3D"top" >
<td align=3D"right" width=3D"163"> <% =3DobjRScbx("Name") %> </td>
<td width=3D"150"><input type=3Dcheckbox name=3Dtxt<%
=3DobjRScbx("Name") %> size=3D20 ></td>
<td bgcolor=3D#cccccc colspan=3D6> </td>
<% objRScbx.MoveNext %>
<% If Not objRScbx.EOF then %>
<td align=3D"right" width=3D"163"><% =3DobjRScbx("Name") %></td>
<td width=3D"150"><input type=3Dcheckbox name=3Dtxt<%
=3DobjRScbx("Name") %> size=3D20 ></td>
<td bgcolor=3D#cccccc colspan=3D6> </td>
</tr>
<% objRScbx.MoveNext
end if
Loop
I want to insert the values that are checked into another table. The
problem is when I try to insert it want.
Example of the what I used to insert:
Set Dconn =3D Server.CreateObject("ADODB.Connection")
Dconn.Open "DSN=3DMyDSN"
SQL =3D "Select Name from TableName"
Set RecordSet =3D Dconn.Execute (SQL)
If Request.Form("txtChange") =3D "checked" then
'Insert data into the table
SQL_Mod=3D"Insert into Table (Num, Name) values ('" &
Request.Form(txtNum) & "','" & Request.Form(txtName) & "')"
ElseIf Request.Form("txtChange") =3D "unchecked" then
'Delete data from table
SQL_Mod=3D"Delete Name from Table where Num =3D '" &
Request.Form("txtNum") &"'"
Dconn.Execute (SQL_Mon)
End If
Dconn.Close
Set Dconn =3D Nothing
%>
Can some one help!!!
|
|
 |