How to allow an url with authentication? - asp.net

I am sending an url to an email by buton click. When the email user is clicking the url he want to face login cardinals. I need to do the job without login cardinals.
Public Function SendMail(ByVal RuequestByEmpId As String, ByVal RuequestToEmpName As String, ByVal RuequestToEmpEmail As String) As Integer
Dim credential As New System.Net.NetworkCredential("joycseuiu#gmail.com", "something")
Dim msg As New System.Net.Mail.MailMessage()
Dim msgSubject As String = String.Empty
Dim strHeading As String = String.Empty
Dim EmployeeID As String = String.Empty
Dim Name As String = String.Empty
Dim Designation As String = String.Empty
Dim Email As String = String.Empty
Dim Department As String = String.Empty
Dim LeaveTYpe As String = String.Empty
Dim Reason As String = String.Empty
Dim LeaveAppID As String = String.Empty
Dim LeaveTo As String = String.Empty
Dim LeaveFrom As String = String.Empty
Dim Status As String = String.Empty
Dim i As Integer = 0
dsEmployeeInfoWithLeaveManagement.SelectParameters("EmployeeID").DefaultValue = RuequestByEmpId
dsEmployeeInfoWithLeaveManagement.DataBind()
dataview = dsEmployeeInfoWithLeaveManagement.Select(System.Web.UI.DataSourceSelectArguments.Empty)
Try
EmployeeID = dataview.Item(0).Row.Item("EmployeeID").ToString()
Name = dataview.Item(0).Row.Item("Name").ToString()
Designation = dataview.Item(0).Row.Item("Designation").ToString()
Department = dataview.Item(0).Row.Item("Department").ToString()
Email = dataview.Item(0).Row.Item("Email").ToString()
LeaveTYpe = dataview.Item(0).Row.Item("LeaveTYpe").ToString()
Reason = dataview.Item(0).Row.Item("Reason").ToString()
LeaveAppID = dataview.Item(0).Row.Item("LeaveAppID").ToString()
LeaveTo = dataview.Item(0).Row.Item("LeaveTo").ToString()
LeaveFrom = dataview.Item(0).Row.Item("LeaveFrom").ToString()
Status = dataview.Item(0).Row.Item("Status").ToString()
Catch ex As Exception
End Try
Dim SenderEmpName As String = "Joy Acharya"
Dim SenderEmpEmail As String = "joycseuiu#gmail.com"
msg.From = New System.Net.Mail.MailAddress(Email, Name)
msg.[To].Add(New System.Net.Mail.MailAddress(RuequestToEmpEmail, RuequestToEmpName))
Dim appSettings = ConfigurationManager.AppSettings
Dim result As String = appSettings("mailSender")
Dim strBody As New StringBuilder()
strBody.Append("<div>" & vbCr & vbLf & "<table>" & vbCr & vbLf & "<tr>" & vbCr & vbLf & "<td>")
msg.Subject = "Leave Application Approve"
strBody.Append("A request for leave has been submitted for your approval.")
strBody.Append("</td>" & vbCr & vbLf & "</tr>" & vbCr & vbLf & "<tr>" & vbCr & vbLf & " <td>" & vbCr & vbLf & "<span>Request By:</span>")
strBody.Append(Name)
strBody.Append("</td>" & vbCr & vbLf & "</tr>" & vbCr & vbLf & "<tr>" & vbCr & vbLf & " <td>" & vbCr & vbLf & "<span>ID:</span>")
strBody.Append(EmployeeID)
strBody.Append("</td>" & vbCr & vbLf & "</tr>" & vbCr & vbLf & "<tr>" & vbCr & vbLf & " <td>" & vbCr & vbLf & "<span>Designation:</span>")
strBody.Append(Designation)
strBody.Append("</td>" & vbCr & vbLf & "</tr>" & vbCr & vbLf & "<tr>" & vbCr & vbLf & " <td>" & vbCr & vbLf & "<span>Department:</span>")
strBody.Append(Department)
strBody.Append("</td>" & vbCr & vbLf & "</tr>" & vbCr & vbLf & "<tr>" & vbCr & vbLf & " <td>" & vbCr & vbLf & "<span>Leave Type:</span>")
strBody.Append(LeaveTYpe)
strBody.Append("</td>" & vbCr & vbLf & "</tr>" & vbCr & vbLf & "<tr>" & vbCr & vbLf & " <td>" & vbCr & vbLf & "<span>Purpose:</span>")
strBody.Append(Reason)
strBody.Append("</td>" & vbCr & vbLf & "</tr>" & vbCr & vbLf & "<tr>" & vbCr & vbLf & " <td>" & vbCr & vbLf & "<span>Leave To:</span>")
strBody.Append(LeaveTo)
strBody.Append("</td>" & vbCr & vbLf & "</tr>" & vbCr & vbLf & "<tr>" & vbCr & vbLf & " <td>" & vbCr & vbLf & "<span>Leave From:</span>")
strBody.Append(LeaveFrom)
strBody.Append("</td></tr>")
strBody.Append("</table>")
strBody.Append("<br />")
strBody.Append("<table>")
strBody.Append("<tr>")
strBody.Append("<td>")
strBody.Append(" " + "<b>Approve</b>" + "")
strBody.Append("</td>")
strBody.Append("<td>")
strBody.Append(" " + "<b>Reject</b>" + "")
strBody.Append("</td>")
strBody.Append("</tr>")
strBody.Append("<table>")
strBody.Append("</div>" & vbCr & vbLf & " <div>" & vbCr & vbLf & " Thank you" & vbCr & vbLf & " <br />")
strBody.Append("=======================================================================================")
strBody.Append("</div>")
msg.Body = strBody.ToString()
msg.IsBodyHtml = True
msg.Priority = System.Net.Mail.MailPriority.High
msg.Priority = System.Net.Mail.MailPriority.High
Dim c As New SmtpClient()
'----------------------------------
'Create the SMTP Client
c.Host = "smtp.gmail.com"
c.Credentials = credential
c.Port = 587
c.EnableSsl = True
Try
c.Send(msg)
Catch ex As Exception
End Try
Return i
End Function
When the email user clicking the Approve link, he has to face the
login cardinals.
I want that, email user will just click the link and he/she will be enable
to redirect the page.
How could i do that.
And thanks in advance.

Related

ADODB.Recordset error '800a0e78' Operation is not allowed when the object is closed

Set RsItem = Conn.Execute("EXEC E_UpdateDevBehaviourSmalls #ClientID=" & Session("ClientID") & " ,#UserID=" & Session("EUserID")& " ,#cCompID=" & cCompetenceid & " ,#reason=" &reason & " ,#comptype=" & comptype &",#GID=" & GID & " ,#Behaviour='" & MakeSendable(Behaviour) & "' ,#Deadline='" & deadlinedatetime & "' ,#DevBehaviour='" & MakeSendable(DevBehaviour) & "' ,#Why='" & MakeSendable(Why) & "' ,#ExtraNote='" & MakeSendable(ExtraNote) & "'")
if GID = 0 then
if not RsItem.eof then
GID = RsItem.fields(0).value
if reason = 0 then
'add dummy devbehaviour detail
Set RsItem =Conn.Execute("EXEC E_UpdateDevBehaviourDetail #ClientID=" & Session("ClientID") & " ,#UserID=" & Session("EUserID") & " ,#GID=" & GID & " ,#DID=0 ,#TextField1='dummy' ,#educ= 0 ,#TextField2='dummy' ,#TextField3='dummy' ,#TextField4='dummy'")
end if
end if
end if
When I try to execute the code above (full code below) I got the following error:
(It gets stuck at the following part: if not RsItem.fields(0).value)
ADODB.Recordset error '800a0e78'
Operation is not allowed when the object is closed.
Can anyone help me with this error?
<%
Dim DID
Dim GID
Dim cCompetenceid
Dim Behaviour
Dim Deadline
Dim DevBehaviour
Dim Why
Dim ExtraNote
MakeConn
Session("OnlinePageID") = 106
InsertLogItem "S:12"
If Session("EUserType")=1 Then
If UCase(Request("Action"))="SAVEDETAIL" Then
If not Request("DID")="" Then
DID = Request("DID")
Else
DID = 0
End If
Conn.Execute("EXEC E_UpdateDevBehaviourDetail #ClientID=" & Session("ClientID") & " ,#UserID=" & Session("EUserID") & " ,#GID=" & Request("GID") & " ,#DID=" & DID & " ,#TextField1='" & MakeSendable(Request("TextField1")) & "' ,#TextField2='" & MakeSendable(Request("TextField2")) & "' ,#TextField3='" & MakeSendable(Request("TextField3")) & "' ,#TextField4='" & MakeSendable(Request("TextField4")) & "'")
Conn.Execute("EXEC E_SignIDP #ClientID=" & Session("ClientID") & " ,#UserID=" & Session("EUserID") & " ,#SignStatus=0")
End If
End If
'response.write Session("EUserType") & "<br>"
If Session("EUserType")=1 Then
Select Case UCase(Request("Action"))
Case "EDIT"
If not Request("GID")="" Then
'response.write "EXEC E_GetDevBehavior #ClientID=" & Session("ClientID") & " ,#UserID=" & Session("EUserID") & " ,#GID=" & Request("GID") & "<br>"
Set RsItem = Conn.Execute("EXEC E_GetDevBehavior #ClientID=" & Session("ClientID") & " ,#UserID=" & Session("EUserID") & " ,#GID=" & Request("GID"))
If not RsItem.EOF Then
Behaviour = Replace (RsItem("Behaviour"),"''","'")
Deadline = RsItem("Deadline")
DevBehaviour = Replace (RsItem("DevBehaviour"),"''","'")
Why = Replace (RsItem("Why"),"''","'")
ExtraNote = Replace (RsItem("ExtraNote"),"''","'")
Else
Response.End
End If
'RsItem.close
'Set RsItem = nothing
Else
End If
Case "SAVE"
If not Request("GID")="" Then
Set RsItem = Conn.Execute("EXEC E_GetDevBehavior #ClientID=" & Session("ClientID") & " ,#UserID=" & Session("EUserID") & " ,#GID=" & Request("GID"))
If not RsItem.EOF Then
Behaviour = Replace (RsItem("Behaviour"),"''","'")
Deadline = RsItem("Deadline")
DevBehaviour = Replace (RsItem("DevBehaviour"),"''","'")
Why = Replace (RsItem("Why"),"''","'")
ExtraNote = Replace (RsItem("ExtraNote"),"''","'")
Else
Response.End
End If
'RsItem.close
'Set RsItem = nothing
end if
dag = Day(Now())
maand = Month(Now())
jaar = Year(Now())
uur = Hour(Time)
minuten = Minute(Time)
seconden = Second(Time)
if len(dag)< 2 then dag ="0" & dag
if len(maand) < 2 then maand ="0" & maand
if len(uur) < 2 then uur ="0" & uur
if len(minuten) < 2 then minuten ="0" & minuten
if len(seconden) < 2 then seconden ="0" & seconden
datum= jaar & "-" & maand & "-" & dag
tijd = uur & ":" & minuten& ":" & seconden
datumtijd = datum & " " & tijd
Conn.Execute("EXEC E_UpdatePOPStartDate #ClientID=" & Session("ClientID") & " ,#UserID=" & Session("EUserID"))
Conn.Execute("EXEC E_UpdateStartDate #ClientID=" & Session("ClientID") & " ,#UserID=" & Session("EUserID") & " ,#StartDate='" & datumtijd & "'")
If not Request("GID")="" Then
GID = Request("GID")
newcomp = false
Else
GID = 0
Deadline = CDate(FormatDate("31/12/"&year(now)))
newcomp = true
End If
'response.write Request("cCompetenceid") &"<br>"
if not Request("cCompetenceid") = "" then
cCompetenceid = Request("cCompetenceid")
else
cCompetenceid = 0
end if
if not Request("reason") = "" then
reason = Request("reason")
else
reason = 0
end if
if not Request("comptype") = "" then
comptype = Request("comptype")
else
comptype = 1
end if
Select Case (Request("COMPID"))
Case 1460
Behaviour = Request("Behaviour")
Case 1461
Deadline = Request("DeadlineDay") & "-" & Request("DeadlineMonth") & "-" & Request("DeadlineYear")
Deadline = CDate(FormatDate(Deadline))
Case 1462
DevBehaviour = Request("DevBehaviour")
Case 1463
Why = Request("Why")
Case 1464
ExtraNote = Request("ExtraNote")
End Select
deadlinedate = CDate(Deadline)
deadlineyear = year(deadlinedate)
deadlinemonth = month(deadlinedate)
deadlineday = day(deadlinedate)
deadlinedatetime = deadlineyear & "-" & deadlinemonth & "-" & deadlineday & " 00:00:00"
'response.write "EXEC E_UpdateDevBehaviourSmalls #ClientID=" & Session("ClientID") & " ,#UserID=" & Session("EUserID")& " ,#cCompID=" & cCompetenceid & " ,#reason=" &reason & " ,#comptype=" & comptype &",#GID=" & GID & " ,#Behaviour='" & MakeSendable(Behaviour) & "' ,#Deadline='" & deadlinedatetime & "' ,#DevBehaviour='" & MakeSendable(DevBehaviour) & "' ,#Why='" & MakeSendable(Why) & "' ,#ExtraNote='" & MakeSendable(ExtraNote) & "'"
'response.end
Set RsItem = Conn.Execute("EXEC E_UpdateDevBehaviourSmalls #ClientID=" & Session("ClientID") & " ,#UserID=" & Session("EUserID")& " ,#cCompID=" & cCompetenceid & " ,#reason=" &reason & " ,#comptype=" & comptype &",#GID=" & GID & " ,#Behaviour='" & MakeSendable(Behaviour) & "' ,#Deadline='" & deadlinedatetime & "' ,#DevBehaviour='" & MakeSendable(DevBehaviour) & "' ,#Why='" & MakeSendable(Why) & "' ,#ExtraNote='" & MakeSendable(ExtraNote) & "'")
if GID = 0 then
if not RsItem.eof then
GID = RsItem.fields(0).value
if reason = 0 then
' add dummy devbehaviour detail
Set RsItem =Conn.Execute("EXEC E_UpdateDevBehaviourDetail #ClientID=" & Session("ClientID") & " ,#UserID=" & Session("EUserID") & " ,#GID=" & GID & " ,#DID=0 ,#TextField1='dummy' ,#educ= 0 ,#TextField2='dummy' ,#TextField3='dummy' ,#TextField4='dummy'")
end if
end if
end if
'RsItem.close
'Set RsItem = nothing
Conn.Execute("EXEC E_SignIDP #ClientID=" & Session("ClientID") & " ,#UserID=" & Session("EUserID") & " ,#SignStatus=0")
if newcomp = true then
tempstr = "../popoverview.asp"
ClientScript("parent.location.href = '../bottomframe.asp?GID=" & GID & "&" & SetID &"&ViewID=4'" )
else
response.write " in"
tempstr = "compoverview.asp?Action=Edit&GID="&GID
response.redirect tempstr
' ClientScript("location.href =" & tempstr)
end if
End Select
End If
conn.close
set conn= nothing
%>
Stored procedure:
USE [Q]
GO
/****** Object: StoredProcedure [dbo].[E_UpdateDevBehaviourSmalls] Script Date: 17/10/2013 15:05:53 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[E_UpdateDevBehaviourSmalls]
(#ClientID int,
#UserID int,
#cCompID int,
#reason int,
#comptype int,
#GID int,
#Behaviour varchar(250),
#Deadline datetime,
#DevBehaviour text,
#Why text,
#ExtraNote text)
AS
If (#GID = 0)
BEGIN
INSERT INTO DevBehaviour(ClientID,UserID,Behaviour,Deadline,DevBehaviour,Why,ExtraNote,cCompId,reason,comptype)
VALUES(#ClientID,#UserID,#Behaviour,#Deadline,#DevBehaviour,#Why,#ExtraNote, #cCompID,#reason,#comptype)
SELECT ##identity
END
Else
BEGIN
UPDATE DevBehaviour
SET Behaviour=#Behaviour, Deadline=#Deadline, DevBehaviour=#DevBehaviour, Why=#Why, ExtraNote=#ExtraNote, cCompId = #cCompID, reason = #reason, comptype = #comptype
WHERE (ClientID = #ClientID) AND (UserID = #UserID) AND (GID = #GID)
END
I was able to reproduce your problem. Please try the stored proc below (using nocount)
USE [Q]
GO
/****** Object: StoredProcedure [dbo].[E_UpdateDevBehaviourSmalls] Script Date: 17/10/2013 15:05:53 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[E_UpdateDevBehaviourSmalls]
(#ClientID int,
#UserID int,
#cCompID int,
#reason int,
#comptype int,
#GID int,
#Behaviour varchar(250),
#Deadline datetime,
#DevBehaviour text,
#Why text,
#ExtraNote text)
AS
set nocount on
If (#GID = 0)
BEGIN
INSERT INTO DevBehaviour(ClientID,UserID,Behaviour,Deadline,DevBehaviour,Why,ExtraNote,cCompId,reason,comptype)
VALUES(#ClientID,#UserID,#Behaviour,#Deadline,#DevBehaviour,#Why,#ExtraNote, #cCompID,#reason,#comptype)
SELECT ##identity
END
Else
BEGIN
UPDATE DevBehaviour
SET Behaviour=#Behaviour, Deadline=#Deadline, DevBehaviour=#DevBehaviour, Why=#Why, ExtraNote=#ExtraNote, cCompId = #cCompID, reason = #reason, comptype = #comptype
WHERE (ClientID = #ClientID) AND (UserID = #UserID) AND (GID = #GID)
END
set nocount off

How to add the email sending script

I'm new to VbScript. I have to make a form for uploading a file and sending to specified email as attachment.
For uploading I used this script http://www.freeaspupload.net/freeaspupload/viewsource.asp
Now my application saves file to server.
The second part looks like this:
<% OPTION EXPLICIT
If Request.Cookies("QuoteRequest") = "Quote" THEN
Dim fileName
Dim strMsg
Dim mail
Dim strSubject
Dim strFrom
Dim strReply
Dim strChoice
Dim AddCheck
Dim MyCheckDate
Dim strMailBlindCopy
Dim smtpserver
Dim youremail
Dim public_mailer
Dim public_password
smtpserver = ""
youremail = ""
public_mailer = ""
public_password = ""
AddCheck = Request.Form("Str_xxrand234Myanswer")
'Use this next line if you want a blind copy send for your records
'strMailBlindCopy = "info#ciupac.com"
'IF AddCheck = "" or NULL THEN
IF len(AddCheck)>2 OR len(AddCheck)<1 OR IsNumeric(AddCheck)=FALSE THEN
response.write "<h2>Sorry an error has occurred, please click here to return to the form</h2>" & AddCheck
Else
Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message")
'This section provides the configuration information for the remote SMTP server.
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpserver
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
' If your server requires outgoing authentication uncomment the lines bleow and use a valid email address and password.
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = public_mailer
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = public_password
ObjSendMail.Configuration.Fields.Update
strFrom = "Quote Request Form"
strReply = Request.Form("txtemail")
strSubject = "Quote Request Form"
strMsg = strMsg & "<b>Your Name:</b> " & Request.Form("txtname") & vbCrLF & vbCrLF & "<BR>" & "<BR>"
strMsg = strMsg & "<b>Your Company Name:</b> " & Request.Form("txtcompany") & vbCrLF & vbCrLF & "<BR>" & "<BR>"
strMsg = strMsg & "<b>Your Order Number:</b> " & Request.Form("txtyourorder") & vbCrLF & vbCrLF & "<BR>" & "<BR>"
strMsg = strMsg & "<b>Our Order Number:</b> " & Request.Form("txtourorder") & vbCrLF & vbCrLF & "<BR>" & "<BR>"
strMsg = strMsg & "<b>Destination Postal Code:</b> " & Request.Form("txtpostal") & vbCrLF & vbCrLF & "<BR>" & "<BR>"
strMsg = strMsg & "<b>Order Date:</b> " & Request.Form("txtdate") & vbCrLF & vbCrLF & "<BR>" & "<BR>"
strMsg = strMsg & "<b>Your E-mail Address:</b> " & Request.Form("txtemail") & vbCrLF & vbCrLF & "<BR>" & "<BR>"
strMsg = strMsg & "<b>Telephone #:</b> " & Request.Form("txtphone") & vbCrLF & vbCrLF & "<BR>" & "<BR>"
strMsg = strMsg & "<b>Comments:</b> " & Request.Form("txtcomments") & vbCrLF & vbCrLF & "<BR>" & "<BR>"
strMsg = strMsg & "<b>Market Served:</b> " & Request.Form("option1") & ", " & Request.Form("option2") & ", " & Request.Form("option3") & ", " & Request.Form("option4") & ", " & Request.Form("option5") & ", " & Request.Form("option6") & ", " & Request.Form("option7") & ", " & Request.Form("option8") & ", " & Request.Form("option9") & ", " & Request.Form("option10") & ", " & Request.Form("option11") & ", " & Request.Form("option12") & ", " & Request.Form("option13") & ", " & Request.Form("option14") & vbCrLF & vbCrLF & "<BR>" & "<BR>"
strMsg = strMsg & "<b>Topic of Interest:</b> " & Request.Form("option15") & ", " & Request.Form("option16") & ", " & Request.Form("option17") & ", " & Request.Form("option18") & ", " & Request.Form("option19") & ", " & Request.Form("option20") & ", " & Request.Form("option21") & ", " & Request.Form("option22") & ", " & Request.Form("option23") & ", " & Request.Form("option24") & ", " & Request.Form("option25") & ", " & Request.Form("option26") & ", " & Request.Form("option27") & ", " & Request.Form("option28") & ", " & Request.Form("option29") & ", " & Request.Form("option30") & ", " & Request.Form("option31") & ", " & Request.Form("option32") & vbCrLF & vbCrLF
fileName = Request.Form("file")
Dim strMailTo
strMailTo =""
ObjSendMail.To = strMailTo
ObjSendMail.Subject = strSubject
ObjSendMail.From = strReply
ObjSendMail.HTMLBody = strMsg
If Len(fileName)Then
ObjSendMail.AddAttachment "C:\attachments\" & fileName
End If
ObjSendMail.Send
Set ObjSendMail = Nothing
Response.Redirect("thank-you.asp")
END IF
ELSE
Dim txtname
Response.Write "ERROR <P>"
fname=Request.Cookies("QuoteRequest")
response.write("QuoteRequest=" & txtname)
END IF
%>
These two scripts work well independently, but when I try to include the email send part to upload the Cannot use Request.Form collection after calling BinaryRead error appears.
How do I need to call the email sender?
Due to the special ENCTYPE="multipart/form-data" attribute of your form, you cannot use the Reqest.Form collection. Use Upload.Form instead, but only after you call Upload.Save (SaveVirtual, SaveToMemory).

unable to execute query in ASP

Following is the ASP code that I am working on:
Dim sConnString, connection, sSQL, backgroundColor
sSQL = "SELECT firstName, lastName, email, zip, country, company, industry, revenue, timestamp FROM users"
sConnString=//a connection string
Set connection = Server.CreateObject("ADODB.Connection")
connection.Mode=adModeRead
connection.Open(sConnString)
connection.execute(sSQL)
Response.Write"<table>"
do while not connection.EOF
if(backgroundColor="#f1f1f1")then
backgroundColor="#ffffff"
else
backgroundColor="#f1f1f1"
end if
response.write"<tr backgroundColor="& backgroundColor & "></td>" & connection("firstName") & "</td><td>" & connection("lastName") & "</td><td>" & connection("email") & "</td><td>" & connection("zip") & "</td><td>" & connection("country") & "</td><td>" & connection("company") & "</td><td>" & connection("industry") & "</td><td>" & connection("revenue") & "</td><td>" & connection("timestamp") & "</td></tr>"
connection.MoveNext
Loop
Response.Write"</table>"
connection.Close
Set connection = Nothing
I am getting the following error:
ADODB.Connection error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/wsu.asp, line 13
Line 13:
do while not connection.EOF
Could you please help me with this?
Updated code:
<html>
<body>
<%
Dim sConnString, connection, sSQL, backgroundColor
sSQL = "SELECT firstName, lastName, email, zip, country, company, industry, revenue, timestamp FROM users"
sConnString="a connection string for MS SQL database;"
Set connection = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
connection.Mode=adModeRead
rs.open sSQL,connection
Response.Write"<table>"
do while not connection.EOF
if(backgroundColor="#f1f1f1")then
backgroundColor="#ffffff"
else
backgroundColor="#f1f1f1"
end if
response.write "<tr backgroundColor="& backgroundColor & "></td>" & connection("firstName") & "</td><td>" & connection("lastName") & "</td><td>" & connection("email") & "</td><td>" & connection("zip") & "</td><td>" & connection("country") & "</td><td>" & connection("company") & "</td><td>" & connection("industry") & "</td><td>" & connection("revenue") & "</td><td>" & connection("timestamp") & "</td></tr>"
connection.MoveNext
Loop
Response.Write"</table>"
connection.Close
Set connection = Nothing
%>
</body>
</html>
See the following edit in your code -
you create a recordset and then open it and execute it
<html>
<body>
<%
Dim sConnString, connection, sSQL, backgroundColor,objrs
sSQL = "SELECT firstName, lastName, email, zip, country, company, industry, revenue, timestamp FROM users"
Set connection = Server.CreateObject("ADODB.Connection")
connection.connectionstring = "put your connection string in here"
' replace put your connection string in here with your connection string
Set objrs= Server.CreateObject("ADODB.Recordset")
connection.Open()
objrs.open sSQL,connection
Response.Write"<table>"
do while not objrs.EOF
if(backgroundColor="#f1f1f1")then
backgroundColor="#ffffff"
else
backgroundColor="#f1f1f1"
end if
response.write"<tr backgroundColor="& backgroundColor & "></td>" & objrs("firstName") & "</td><td>" & objrs("lastName") & "</td><td>" & objrs("email") & "</td><td>" & objrs("zip") & "</td><td>" & objrs("country") & "</td><td>" & objrs("company") & "</td><td>" & objrs("industry") & "</td><td>" & objrs("revenue") & "</td><td>" & objrs("timestamp") & "</td></tr>"
objrs.MoveNext
Loop
Response.Write"</table>"
%>
</body>
</html>
a note:--
this needs to be something like - not sure what database you are using -
sConnString= "Provider=sqloledb;Data Source=ServerName;Initial Catalog=DatebaseName "
or if you have a dsn connection then simply
sConnString = "DSN=xxxxx;uid=xxx;pwd=xxx"
You will need to create a Recordset to read the data from your SQL query. You have used connection itself.
try below example.
HERE

how to use <a href ></a> in classic asp?

i have three columns column(0),column(1),column(2)and i want tag for these three columns in following code for this line: "strNewContents = strNewContents & "" & columns(0) & "" & columns(1) & "" & columns(2) & "" & vbcrlf:"
actual code:
Dim strFileName1
Dim objFSO, objTextFile
Dim intLineNumber, strNewContents, strReadLineText,strLineNumbers
dim data, columns
strFileName1 = "saveimagename.txt"
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(Server.MapPath(strFileName1))
intLineNumber = 0
strLineNumbers = ""
data = split(objTextFile.readall(), vbcrlf)
for intLineNumber = 0 to ubound(data)
columns = split(data(intLineNumber), ",", 3)
if (ubound(columns) = 2) then
''//strNewContents = "<td class='red'>" & columns(0) & "</td><td class='blue'>" & columns(2) & "</td>"
strNewContents = strNewContents & "<tr><td>" & columns(0) & "</td><td>" & columns(1) & "</td><td>" & columns(2) & "</td></tr>" & vbcrlf
end if
next
You are already using Response.Write with strings.
You simply:
Response.Write "" & linkName & ""

GridView isn't paging or sorting when inside a user control

My Gridview won't page or sort. By this I mean that the data in the GridView doesn't change when I try to sort by a column or when I try to page through the GridView.
I have it inside an UpdatePanel on a user control (.ascx). The code below works fine when I try it outside of the user control.
Here's my code:
<asp:GridView runat="server" ID="grdStats" AutoGenerateColumns="false" Width="100%" AllowSorting="true"
AllowPaging="true" PageSize="20" PagerSettings-Mode="NumericFirstLast" PagerSettings-Position="TopAndBottom">
<Columns>
<asp:BoundField DataField="campaignname" HeaderText="Campaign Name" SortExpression="campaignname" />
<asp:BoundField DataField="site_name" HeaderText="Outlet" SortExpression="site_name" />
<asp:BoundField DataField="filename" HeaderText="Media" SortExpression="filename" />
<asp:BoundField DataField="playinterval" HeaderText="Play Interval" SortExpression="playinterval" />
</Columns>
</asp:GridView>
Here's the backend:
Protected Sub grdStats_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdStats.PageIndexChanging
grdStats.PageIndex = e.NewPageIndex
GetCampaignData()
End Sub
Protected Sub grdStats_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles grdStats.Sorting
If e.SortExpression = ViewState("sortExpr") Then
ViewState("sortExpr") = e.SortExpression & " desc"
Else
ViewState("sortExpr") = e.SortExpression
End If
GetCampaignData()
End Sub
' ######## POPULATE DATA #########
Private Sub GetCampaignData(Optional ByVal CompanyID As Integer = 0)
Dim sql As String = Nothing
' Check user access level.
If Session("userlevel") = 1 Then
' Current user is admin.
' If a company has been filtered, get it's data, else, get all campaign data.
If CompanyID <> 0 Then
sql = "SELECT" & vbCrLf & _
" a.campaignid," & vbCrLf & _
" a.companyid," & vbCrLf & _
" a.campaignname," & vbCrLf & _
" a.filename," & vbCrLf & _
" startdate," & vbCrLf & _
" enddate," & vbCrLf & _
" a.playinterval," & vbCrLf & _
" a.ActiveStatus," & vbCrLf & _
" b.*," & vbCrLf & _
" (SELECT COUNT(*)" & vbCrLf & _
" FROM campaignstats AS c" & vbCrLf & _
" WHERE DAY(date_played) = DAY(CURRENT_DATE)" & vbCrLf & _
" AND c.campaignid = a.campaignid" & vbCrLf & _
" ) AS today," & vbCrLf & _
" (SELECT COUNT(*)" & vbCrLf & _
" FROM campaignstats AS d" & vbCrLf & _
" WHERE date_played > CURRENT_DATE - INTERVAL 7 DAY" & vbCrLf & _
" AND d.campaignid = a.campaignid" & vbCrLf & _
" ) AS past_week," & vbCrLf & _
" (SELECT COUNT(*)" & vbCrLf & _
" FROM campaignstats AS e" & vbCrLf & _
" WHERE e.campaignid = a.campaignid" & vbCrLf & _
" ) AS playcount" & vbCrLf & _
"FROM campaigns AS a" & vbCrLf & _
"INNER JOIN companies AS b ON a.companyid = b.companyid" & vbCrLf & _
"WHERE a.ActiveStatus = 1" & vbCrLf & _
"AND a.companyid = " & CompanyID
Else
sql = "SELECT" & vbCrLf & _
" a.campaignid," & vbCrLf & _
" a.companyid," & vbCrLf & _
" a.campaignname," & vbCrLf & _
" a.filename," & vbCrLf & _
" startdate," & vbCrLf & _
" enddate," & vbCrLf & _
" a.playinterval," & vbCrLf & _
" a.ActiveStatus," & vbCrLf & _
" b.*," & vbCrLf & _
" (SELECT COUNT(*)" & vbCrLf & _
" FROM campaignstats AS c" & vbCrLf & _
" WHERE DAY(date_played) = DAY(CURRENT_DATE)" & vbCrLf & _
" AND c.campaignid = a.campaignid" & vbCrLf & _
" ) AS today," & vbCrLf & _
" (SELECT COUNT(*)" & vbCrLf & _
" FROM campaignstats AS d" & vbCrLf & _
" WHERE date_played > CURRENT_DATE - INTERVAL 7 DAY" & vbCrLf & _
" AND d.campaignid = a.campaignid" & vbCrLf & _
" ) AS past_week," & vbCrLf & _
" (SELECT COUNT(*)" & vbCrLf & _
" FROM campaignstats AS e" & vbCrLf & _
" WHERE e.campaignid = a.campaignid" & vbCrLf & _
" ) AS playcount" & vbCrLf & _
"FROM campaigns AS a" & vbCrLf & _
"INNER JOIN companies AS b ON a.companyid = b.companyid" & vbCrLf & _
"WHERE a.ActiveStatus = 1"
End If
Else
' User is not an admin.
sql = "SELECT" & vbCrLf & _
" a.campaignid," & vbCrLf & _
" a.companyid," & vbCrLf & _
" a.campaignname," & vbCrLf & _
" a.filename," & vbCrLf & _
" startdate," & vbCrLf & _
" enddate," & vbCrLf & _
" a.playinterval," & vbCrLf & _
" a.ActiveStatus," & vbCrLf & _
" b.*," & vbCrLf & _
" (SELECT COUNT(*)" & vbCrLf & _
" FROM campaignstats AS c" & vbCrLf & _
" WHERE DAY(date_played) = DAY(CURRENT_DATE)" & vbCrLf & _
" AND c.campaignid = a.campaignid" & vbCrLf & _
" ) AS today," & vbCrLf & _
" (SELECT COUNT(*)" & vbCrLf & _
" FROM campaignstats AS d" & vbCrLf & _
" WHERE date_played > CURRENT_DATE - INTERVAL 7 DAY" & vbCrLf & _
" AND d.campaignid = a.campaignid" & vbCrLf & _
" ) AS past_week," & vbCrLf & _
" (SELECT COUNT(*)" & vbCrLf & _
" FROM campaignstats AS e" & vbCrLf & _
" WHERE e.campaignid = a.campaignid" & vbCrLf & _
" ) AS playcount" & vbCrLf & _
"FROM campaigns AS a" & vbCrLf & _
"INNER JOIN companies AS b ON a.companyid = b.companyid" & vbCrLf & _
"WHERE a.ActiveStatus = 1" & vbCrLf & _
"AND a.companyid = " & CInt(Session("companyid"))
End If
grdCampaigns.DataSource = get_data(sql)
grdCampaigns.DataBind()
For i As Integer = 0 To grdCampaigns.Rows.Count - 1
grdCampaigns.Rows(i).Cells(2).Text = Microsoft.VisualBasic.Left(grdCampaigns.Rows(i).Cells(2).Text, 10)
grdCampaigns.Rows(i).Cells(3).Text = Microsoft.VisualBasic.Left(grdCampaigns.Rows(i).Cells(3).Text, 10)
Next
End Sub
Public Function get_data(ByVal SQLStatement As String) As DataView
'Populates the datatable
Dim dt As Data.DataTable
dt = db.GetDataTable(SQLStatement)
Dim dv As System.Data.DataView = New System.Data.DataView(dt)
If Not ViewState("sortExpr") Is Nothing Then
dv.Sort = ViewState("sortExpr")
Else
dv = dt.DefaultView
End If
Session("dv5") = dv
Return dv
End Function
Any help would be greatly appreciated.
My apologies the code I pasted in the question, although correct for it's purpose, was not the right code relevant to this question. That said, I'd like to thank you Icarus for taking the time to look over my code.
The paging/sorting works. What I did to fix it was to replace the call to GetCampaignData() within the PageIndexChanging and Sorting event handlers to the SQL code and data binding methods required to give me the results I needed.

Resources