|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Delete a row??
I have a report that queries a database and outputs a table. I would like to have the functionallity to delete a row of the table on the report as well as from the table in the database. What would be the best way to do this? A column with a delete button next to each row would be the best. How would I go about doing this? Here is my report code:
Code:
<%
Dim oConn, oRS, strConn, URLRedirTo, strOut
Dim strErrorMessage, sqltest
Dim objCmd, objParam, strRs, strReturn
Set oConn = Server.CreateObject ("ADODB.Connection")
oConn.Open "DSN=***;User Id=***; Password=***"
Set oRS=Server.CreateObject("ADODB.recordset")
sqltext = "SELECT SessionId,StartTime,UserName,NASIP,NASIdentifier,"
sqltext = sqltext & "FramedAddress,CallingStationId FROM ActiveSessions WHERE UserName NOT LIKE 'W00%'ORDER BY UserName;"
oRS.Open sqltext, oConn
%>
<%
If oRS.EOF <> True Then
Response.Write("<TABLE BORDER=""1"">")
Response.Write("<THREAD><TR><TD><STRONG>SessionId</STRONG></TD>")
Response.Write("<TD><STRONG>StartTime</STRONG></TD>")
Response.Write("<TD><STRONG>UserName</STRONG></TD>")
Response.Write("<TD><STRONG>NASIP</STRONG></TD>")
Response.Write("<TD><STRONG>NASIdentifier</STRONG></TD>")
Response.Write("<TD><STRONG>FramedAddress</STRONG></TD>")
Response.Write("<TD><STRONG>CallingStationId</STRONG></TD></TR></THREAD>")
While Not oRS.EOF
Response.Write("<TR><TD>" & oRS("SessionId") & "</TD>" & vbCrLf)
Response.Write("<TD>" & oRS("StartTime") & "</TD>" & vbCrLf)
Response.Write("<TD>" & oRS("UserName") & "</TD>" & vbCrLf)
Response.Write("<TD>" & oRS("NASIP") & "</TD>" & vbCrLf)
Response.Write("<TD>" & oRS("NASIdentifier") & "</TD>" & vbCrLf)
Response.Write("<TD>" & oRS("FramedAddress") & "</TD>" & vbCrLf)
Response.Write("<TD>" & oRS("CallingStationId") & "</TD>" & vbCrLf)
Response.Write("</tr>" & vbCrLf)
oRS.MoveNext
wend
Response.Write("</table>")
Else
URLRedirTo = "NoUsersOnLine.html"
Response.Redirect URLRedirTo
End If
oRS.close : oConn.close
Set oRS = Nothing : Set oConn = Nothing
Set objParam = Nothing : Set objCmd = Nothing
%>
Last edited by Cozilla : July 2nd, 2009 at 02:31 PM. |
|
#2
|
|||
|
|||
|
The unique identifier would be the sessionId. Just not sure how i would go about pulling that sessionId from the line then using it in the sql statement.
|
|
#3
|
||||
|
||||
|
Hi,
If you wanted to remove the rows from both the HTMl table and the database table in the clientside you would need to use AJAX. Heres an example that doesnt use AJAX, instead, it just submits the form and passes the value of the SessionID in the form collection. The page then loops through the forms collection and deletes the corresponding record, then displays the html table minus the row. Maybe not the best solution but may give you some ideas: Code:
<%
Dim oConn, oRS, strConn, URLRedirTo, strOut
Dim strErrorMessage, sqltest
Dim objCmd, objParam, strRs, strReturn
Set oConn = Server.CreateObject ("ADODB.Connection")
oConn.Open "DSN=***;User Id=***; Password=***"
For Each x in Request.Form
If Left(x, 6) = "btnDel" Then
sqltext = "DELETE FROM ActiveSessions WHERE SessionID = " & Mid(x, InStr(x, "|")+1)
oConn.Execute(sql)
End If
Next
Set oRS=Server.CreateObject("ADODB.recordset")
sqltext = "SELECT SessionId,StartTime,UserName,NASIP,NASIdentifier,"
sqltext = sqltext & "FramedAddress,CallingStationId FROM ActiveSessions WHERE UserName NOT LIKE 'W00%'ORDER BY UserName;"
oRS.Open sqltext, oConn
%>
<%
Response.Write("<form name=""delForm"" method=""post"" action=""yourpage.asp"">")
If oRS.EOF <> True Then
Response.Write("<TABLE BORDER=""1"">")
Response.Write("<THREAD><TR><TD width=""5%""> </TD><TD><STRONG>SessionId</STRONG></TD>")
Response.Write("<TD><STRONG>StartTime</STRONG></TD>")
Response.Write("<TD><STRONG>UserName</STRONG></TD>")
Response.Write("<TD><STRONG>NASIP</STRONG></TD>")
Response.Write("<TD><STRONG>NASIdentifier</STRONG></TD>")
Response.Write("<TD><STRONG>FramedAddress</STRONG></TD>")
Response.Write("<TD><STRONG>CallingStationId</STRONG></TD></TR></THREAD>")
While Not oRS.EOF
Response.Write("<TR><TD><input type=""submit"" value=""Delete"" name=""btnDel|" & oRS("SessionId") & """></TD>")
Response.Write("<TD>" & oRS("SessionId") & "</TD>" & vbCrLf)
Response.Write("<TD>" & oRS("StartTime") & "</TD>" & vbCrLf)
Response.Write("<TD>" & oRS("UserName") & "</TD>" & vbCrLf)
Response.Write("<TD>" & oRS("NASIP") & "</TD>" & vbCrLf)
Response.Write("<TD>" & oRS("NASIdentifier") & "</TD>" & vbCrLf)
Response.Write("<TD>" & oRS("FramedAddress") & "</TD>" & vbCrLf)
Response.Write("<TD>" & oRS("CallingStationId") & "</TD>" & vbCrLf)
Response.Write("</tr>" & vbCrLf)
oRS.MoveNext
wend
Response.Write("</table>")
Else
URLRedirTo = "NoUsersOnLine.html"
Response.Redirect URLRedirTo
End If
Response.Write("</form>")
oRS.close : oConn.close
Set oRS = Nothing : Set oConn = Nothing
Set objParam = Nothing : Set objCmd = Nothing
%>
|
|
#4
|
|||
|
|||
|
Quote:
What you posted is exactly what i want it to do but i tried your code and in my logfile im getting the following error: Code:
|16|800a01a8|Object_required:_' ' This is the code, line 16 is bolded. I tried replacing (sql) with (sqltext) and i get the same thing. Code:
<%
Dim oConn, oRS, strConn, URLRedirTo, strOut
Dim strErrorMessage, sqltest
Dim objCmd, objParam, strRs, strReturn
For Each x in Request.Form
If Left(x, 6) = "btnDel" Then
sqltext = "DELETE FROM ActiveSessions WHERE SessionID = " & Mid(x, InStr(x, "|")+1)
oConn.Execute(sql)
End If
Next
Set oConn = Server.CreateObject ("ADODB.Connection")
oConn.Open "DSN=***;User Id=***; Password=***"
Set oRS=Server.CreateObject("ADODB.recordset")
sqltext = "SELECT SessionId,StartTime,UserName,NASIP,NASIdentifier,"
sqltext = sqltext & "FramedAddress,CallingStationId FROM ActiveSessions WHERE UserName NOT LIKE 'W00%'ORDER BY UserName;"
oRS.Open sqltext, oConn
%>
Thanks! |
|
#5
|
||||
|
||||
|
Can you post the html generated by the code so I can see what the buttons name contains?
Also, Can you display the contents of the sql variable and post the results: Code:
<%
If Left(x, 6) = "btnDel" Then
sqltext = "DELETE FROM ActiveSessions WHERE SessionID = " & Mid(x, InStr(x, "|")+1)
Response.Write(sql)
Response.End
oConn.Execute(sql)
End If
|
|
#6
|
|||
|
|||
|
Quote:
The sql variable isnt anything. The response write did not out put anything. I have included the html output. |
|
#7
|
||||
|
||||
|
Quote:
My mistake, can you display the contents of your sql variable, is it sqlText? |
|
#8
|
||||
|
||||
|
With regards the html output, any chance you could view the source of the page and post the actual html code? I am only interested in the code behind the buttons so you can remove everything else so that you dont display any sensitive information.
|
|
#9
|
|||
|
|||
|
thats weird cuz the output is correct. I used the first row as shown in the pic i attached and this is what the response was:
Code:
DELETE FROM ActiveSessions WHERE SessionID = 000A3D0D |
|
#10
|
||||
|
||||
|
It worked for me when I tested it because my session ids were numeric, you would need to surround yours with single quotes:
Code:
sqltext = "DELETE FROM ActiveSessions WHERE SessionID = '" & Mid(x, InStr(x, "|")+1) & "' " |
|
#11
|
|||
|
|||
|
just tried that too im still getting the same error.
Do you think it has something to do with the oConn? |
|
#12
|
||||
|
||||
|
Quote:
|
|
#13
|
|||
|
|||
|
Quote:
Code:
<%
Dim oConn, oRS, strConn, URLRedirTo, strOut
Dim strErrorMessage, sqltest
Dim objCmd, objParam, strRs, strReturn
For Each x in Request.Form
If Left(x, 6) = "btnDel" Then
sqltext = "DELETE FROM ActiveSessions WHERE SessionID = '" & Mid(x, InStr(x, "|")+1) & "' "
oConn.Execute(sqltext)
End If
Next
Set oConn = Server.CreateObject ("ADODB.Connection")
oConn.Open "DSN=**;User Id=**; Password=**"
Set oRS=Server.CreateObject("ADODB.recordset")
sqltext = "SELECT SessionId,StartTime,UserName,NASIP,NASIdentifier,"
sqltext = sqltext & "FramedAddress,CallingStationId FROM ActiveSessions WHERE UserName NOT LIKE 'W00%'ORDER BY UserName;"
oRS.Open sqltext, oConn
%>
|
|
#14
|
||||
|
||||
|
You need to declare the connection first:
Code:
<%
Dim oConn, oRS, strConn, URLRedirTo, strOut
Dim strErrorMessage, sqltest
Dim objCmd, objParam, strRs, strReturn
Set oConn = Server.CreateObject ("ADODB.Connection")
oConn.Open "DSN=**;User Id=**; Password=**"
For Each x in Request.Form
If Left(x, 6) = "btnDel" Then
sqltext = "DELETE FROM ActiveSessions WHERE SessionID = '" & Mid(x, InStr(x, "|")+1) & "' "
oConn.Execute(sqltext)
End If
Next
Set oRS=Server.CreateObject("ADODB.recordset")
sqltext = "SELECT SessionId,StartTime,UserName,NASIP,NASIdentifier,"
sqltext = sqltext & "FramedAddress,CallingStationId FROM ActiveSessions WHERE UserName NOT LIKE 'W00%'ORDER BY UserName;"
oRS.Open sqltext, oConn
%>
|
|
#15
|
|||
|
|||
|
I moved the set oConn above the For Each and that was the trick
Sync or Swim thank you so much for all of your help! |
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > Delete a row?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|