How I can get first value of database for each id_ope? [closed] - asp-classic

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
My data missing for first row when id_ope change
when I query data from the database it shows like this below
And after coding
this is my code in ASP-classic
test = 0
for x = 0 to emailRow
id_ope = arrx(0,x)
id_boat = arrx(1,x)
bname = arrx(2,x)
' email = arrx(3,x)
body = "<table>"&arrcon&"<table>"
if id_ope&"" <> "2" then
if test = 0 then
test = id_ope
content = "<tr><td>"&bname&id_ope&"</td><td>"&id_boat&"</td></tr>"
arrcon = arrcon +content
elseif test = id_ope then
content = "<tr><td>"&bname&id_ope&"</td><td>"&id_boat&"</td></tr>"
arrcon = arrcon +content
else
content = "<tr><td>"&bname&id_ope&"</td><td>"&id_boat&"</td></tr>"
arrcon = arrcon +content
mailBody = body
arrcon = ""
test = id_ope
response.write mailBody
end if
end if
next
And this is my SQL query
SELECT DISTINCT TOP 30 boat.id_ope,
boat.id_boat,
boat.Name2
FROM Boat
INNER JOIN Commission ON Commission.id_boat = Boat.id_boat
WHERE Commission.Commission = '0'
ORDER BY boat.id_ope DESC;

See in comment code
content = "<tr><td>"&bname&id_ope&"</td><td>"&id_boat&"</td></tr>"
arrcon = arrcon +content // add value
mailBody = body
arrcon = "" //set = null
test = id_ope
response.write mailBody
I think your set arrcon = "" after add value

Related

Item cannot be found in the collection to the requested name or ordinal

Upon clicking a client from the datagrid, all the clients informaition are loaded in the right side of the form, all seems to be doing pretty well.[https://i.stack.imgur.com/Mv5ZL.png][1]
and whenever I click the add payment button, it will open the payment form.
[https://i.stack.imgur.com/DmznP.png][2]
but whenever I try to choose another client, it will produce a runtime error '3265'. and when I click the debug button, the fields to be filled seemed to have all the information they needed. Why is this error showing up? [https://i.stack.imgur.com/YuLg5.png][3]
Here is my code in loading all the clients
Private Sub Form_Load()
Set Connect = New Class1
Set rx = New ADODB.Recordset
rx.Open "SELECT * FROM allclients ORDER by dateCreated ASC", con, 3, 3
lblLNumberRecords.Caption = Format(rx.RecordCount, "###,###,###.##")
Set DatCUSTOMERS.DataSource = rx
Me.Show
clearfields
End Sub
and here is my code when clicking a client:
Private Sub DatCUSTOMERS_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Unload frmPaymentRecur
lblID = rx.Fields("id")
txtClientID = rx.Fields("clientCode")
txtFirstName = rx.Fields("fname")
txtLastName = rx.Fields("lname")
txtMname = rx.Fields("mname")
txtExtension = rx.Fields("extName")
txtPin = rx.Fields("pinNo")
txtDesignation = rx.Fields("designation")
txtContactNo = rx.Fields("contactNo")
txtAddress = rx.Fields("address")
txtAge = rx.Fields("Age")
txtSalary = rx.Fields("salary")
cmbAssociation.Text = rx.Fields("fieldTypeTitle")
cmbChoices.Text = rx.Fields("fieldNameTitle")
cmdEdit.Enabled = True
cmdAddLoan.Enabled = True
cmdPayments.Enabled = True
End Sub
here is my code when clicking the add payment button:
Private Sub cmdPayments_Click()
Dim flagClients, dateFlag, loanFlag As Integer
flagClients = 1
dateFlag = 1
loanFlag = 1
frmPaymentRecur.lbldateFlag.Caption = dateFlag
frmPaymentRecur.lblLoanFlag.Caption = loanFlag
frmPaymentRecur.txtClientID = rx.Fields("clientCode")
frmPaymentRecur.txtFolderNo = rx.Fields("folderCode")
frmPaymentRecur.txtFullName = rx.Fields("Name")
frmPaymentRecur.txtAssociation = rx.Fields("fieldNameTitle")
frmPaymentRecur.txtSalary = rx.Fields("salary")
frmPaymentRecur.CmbSelectPaymentType.Text = "All Loans"
frmPaymentRecur.lblFlag = flagClients
If rx.State = 1 Then rx.Close
rx.Open "SELECT DISTINCT(`Loan Type`) FROM paymentview WHERE `Client Code` = '" & Trim$(txtClientID.Caption) & "'", con, 3, 3
With rx
Do While Not .EOF
frmPaymentRecur.CmbSelectPaymentType.AddItem ![Loan Type]
.MoveNext
Loop
.Close
End With
frmPaymentRecur.Show
End Sub
In your Add Payment code, at the end, you are closing the rx recordset. It will be empty when you try updating your controls.
You've also populated the recordset with data form a different table, paymentview, where id probably doesn't exist.
You should create a separate recordset to handle your payment code instead of reusing the rx recordset.

Passing array into table

I'm creating multiple choice question system.
So far i create these 4 tables and 1 view.
The tables are tblQuestion, tblAnswer, tblQuiz, tblResult and tblResultDetail.
tblQuestion is to store the questions, tblAnswer to store the answers of the question,tblResult is to record for every user that answers the quiz, and store the users answers in TblResultDetails.
Based on the code below, the data is read from view. (questiondr.Read). I use 1 , 2 , 3, 4 as it is the column name of the view. I did this to randomize the answers.
Dim MyArray(3) As String
Dim commd As New SqlCommand("Select * From view_Question Where =QuestionID=#IdQuestion", conn)
commd.Parameters.AddWithValue("#IdQuestion", count)
Dim questiondr As SqlDataReader
questiondr = commd.ExecuteReader
If questiondr.Read() Then
Me.lblTitle.Text = questiondr("txtQuestion")
Me.ansrb1.Text = questiondr("1")
MyArray(0) = questiondr("1")
Me.ansrb2.Text = questiondr("2")
MyArray(1) = questiondr("2")
Me.ansrb3.Text = questiondr("3")
MyArray(2) = questiondr("3")
Me.ansrb4.Text = questiondr("4")
MyArray(3) = questiondr("4")
Dim userAns As String
If Me.ansrb1.Checked = True Then
userAns = MyArray(0)
ElseIf Me.ansrb2.Checked = True Then
answerId = MyArray(1)
ElseIf Me.ansrb3.Checked = True Then
userAns = MyArray(2)
ElseIf Me.ansrb4.Checked = True Then
userAns = MyArray(3)
End If
End If
conn.Close()
End Sub
And the problem is, how to pass the users answers into table tblResultDetails?
Supposing that tblResultDetails contains a field for the userid, a field for the questionid and a field for the answer given by that particular user to that particular question then you need something like this
Dim cmdText = "INSERT INTO tblResultDetails VALUES (#userid, #questionid, #answerid)"
Dim cmd = new SqlCommand(cmdText, connection)
cmd.Parameters.AddWithValue("#userid", yourCurrentUserIDValue)
cmd.Parameters.AddWithValue("#questionid", yourCurrentQuestionIDValue)
cmd.Parameters.AddWithValue("#answerid", userAns)
cmd.ExecuteNonQuery()
As you can see it is pretty straightforward if you have stored somewhere the two missing informations (userid and questionid)

ASP grab two parameters from referral url

Hi I am using a code to get the referral URL as you can see below:
sRef = encode(Request.ServerVariables("HTTP_REFERER"))
The code above is getting the following URL:
http://www.rzammit.com/pages/linux-form.asp?adv=101&loc=349&websync=233344-4555665-454&ptu=454545
From that url I want to grab ONLY the ADV and LOC (Request.querystring doesnt work because this is a script which is run when the form is submitted)
So to cut the story short, by using the referral URL, i want to get out the values for the adv and loc parameters.
Any help please on how I can do this?
Below is the code I am currently using but I have a problem. The parameters which are after the loc, is showing as well. I want something dynamic. Also the values of the adv and loc can be longer.
<%
sRef = Request.ServerVariables("HTTP_REFERER")
a=instr(sRef, "adv")+4
b=instr(sRef, "&loc")
response.write(mid(sRef ,a,b-a))
response.write("<br>")
response.write(mid(sRef ,b+5))
%>
Here is something to get you started; it uses regular expressions to get all URL variables for you. You can use the split() function to split them on the "=" sign and get a simple array, or put them in a dictionary or whatever.
Dim fieldcontent : fieldcontent = "http://www.rzammit.com/pages/linux-form.asp?adv=101&loc=349&websync=233344-4555665-454&ptu=454545"
Dim regEx, Matches, Item
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.MultiLine = False
regEx.Pattern = "(\?|&)([a-zA-Z0-9]+)=([^&])"
Set Matches = regEx.Execute(fieldcontent)
For Each Item in Matches
response.write(Item.Value & "<br/>")
Next
Set regEx = Nothing
substring everything after the ?.
Split on "&"
Iterate the array to find "adv=" and "loc="
Below is the code:
Dim fieldcontent
fieldcontent = "http://www.rzammit.com/pages/linux-form.asp?adv=101&loc=349&websync=233344-4555665-454&ptu=454545"
fieldcontent = mid(fieldcontent,instr(fieldcontent,"?")+1)
Dim params
params = Split(fieldcontent,"&")
for i = 0 to ubound(params) + 1
if instr(params(i),"adv=")>0 then
advvalue = mid(params(i),len("adv=")+1)
end if
if instr(params(i),"loc=")>0 then
locvalue = mid(params(i),5)
end if
next
You can use the following generic function:
function getQueryStringValueFromUrl(url, key)
dim queryString, queryArray, i, value
' check if a querystring is present
if not inStr(url, "?") > 0 then
getQueryStringValueFromUrl = empty
end if
' extract the querystring part from the url
queryString = mid(url, inStr(url, "?") + 1)
' split the querystring into key/value pairs
queryArray = split(queryString, "&")
' see if the key is present in the pairs
for i = 0 to uBound(queryArray)
if inStr(queryArray(i), key) = 1 then
value = mid(queryArray(i), len(key) + 2)
end if
next
' return the value or empty if not found
getQueryStringValueFromUrl = value
end function
In your case:
dim url
url = "http://www.rzammit.com/pages/linux-form.asp?adv=101&loc=349&websync=233344-4555665-454&ptu=454545"
response.write "ADV = " & getQueryStringValueFromUrl(url, "adv") & "<br />"
response.write "LOC = " & getQueryStringValueFromUrl(url, "loc")

Json.Net deserialize anonymous type [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Deserializing JSON into an object with Json.NET
Any ideas of how to deserialize the following response into anonymous type using Json.Net?
{"d":[{"day":"Wednesday","firstSet":{"start":"17:00","close":"23:00","hours":6,"isValid":true},"secondSet":{"start":"00:00","close":"00:00","hours":0,"isValid":false},"personMinimum":2,"personMaximum":25}]}
Attempts so far result in the following error
Could not cast or convert from System.String to <>f__AnonymousType35[System.String,<>f__AnonymousType24[System.String,System.String,System.Int32,System.Boolean],<>f__AnonymousType2`4[System.String,System.String,System.Int32,System.Boolean],System.Int32,System.Int32].
Code is supplied below
var json_complex = new
{
d = new
{
day = "",
firstSet = new
{
start = "",
close = "",
hours = 0,
isValid = false
},
secondSet = new
{
start = "",
close = "",
hours = 0,
isValid = false
},
personMinimum = 2,
personMaximum = 25
}
};
var json = JsonConvert.DeserializeAnonymousType(jsonResponse, json_complex);
Any ideas?
First of all I must say why are you including third party into your application ?
Asp.net provides JavaScriptSerializer for serialization !
Look at my question and refer the answer you can get idea from this

Clearing multiple cookies

The code below tries to clear the cookies for all domains once a user logs out of the system. For some reason, only the last domain in the array is cleared. Why does this happen? Am I doing something wrong?
For example, if I change the size of the array to 4 and then change the for loop to only go to 3, then it only logs me out of y.xcv.com.
As a sidenote, I have this loop working on a different server that uses a slightly different function to clear the cookies.
Edit: Code updated per suggestions below. Now it fails on the "as HttpCookie" line. Do I need to include some library?
Dim aDomain(12)
Dim ESidCookie, WIdCookie, EBidCookie, TSidAccessCookie, PSidAccessCookie, SSidCookie As HttpCookie
aDomain(0) = ".x.com"
aDomain(1) = "y.x.com"
aDomain(2) = "y.x.com"
aDomain(3) = "y.xcv.com"
aDomain(4) = "x.com"
aDomain(5) = "y.z.a.com"
aDomain(6) = "y.z.a.com"
aDomain(7) = "z.a.com"
aDomain(8) = ""
aDomain(9) = "y.x.com"
aDomain(10) = "y.x.com"
aDomain(11) = "y.x.com"
for count = 0 to 11
strDomain = aDomain(count)
response.Write count & "/" & strDomain
ESidCookie = New HttpCookie("oneCookie")
ESidCookie.Domain = strDomain
ESidCookie.Path = "/"
ESidCookie = ""
ESidCookie.Expires = now() - 100
Response.Cookies.Add(ESidCookie)
WIdCookie = New HttpCookie("twoCookie")
WIdCookie.Domain = strDomain
WIdCookie.Path = "/"
WIdCookie = ""
WIdCookie.Expires = now() - 100
Response.Cookies.Add(WIdCookie)
EBidCookie = New HttpCookie("threeCookie")
EBidCookie.Domain = strDomain
EBidCookie.Path = "/"
EBidCookie = ""
EBidCookie.Expires = now() - 100
Response.Cookies.Add(EBidCookie)
TSidAccessCookie = New HttpCookie("fourCookie")
TSidAccessCookie.Path = "/"
TSidAccessCookie = "LoggedOut"
Response.Cookies.Add(TSidAccessCookie)
PSidAccessCookie = New HttpCookie("fiveCookie")
PSidAccessCookie.Domain = strDomain
PSidAccessCookie.Path = "/"
PSidAccessCookie = ""
PSidAccessCookie.Expires = now() - 100
Response.Cookies.Add(PSidAccessCookie)
SSidCookie = New HttpCookie("sixCookie")
SSidCookie.Domain = strDomain
SSidCookie.Path = "/"
SSidCookie = ""
SSidCookie.Expires = now() - 100
Response.Cookies.Add(SSidCookie)
next
Any help is appreciated. Thanks!
The Response.Cookies collection is keyed off of the cookie name so you are just changing the domain of the same cookie each time you go through your loop. That's why the last one wins.
You could try creating a new cookie object and adding that to the Response.Cookies collection in your loop instead.
If you want to clear all cookies you will should create all new ones with the same name. Here is a basic example that should get you going:
Dim newCookie As HttpCookie
For i As Integer = 0 To 10
' creating a new cookie each time
newCookie = New HttpCookie(cookieNames(i))
' expire the cookie
newCookie.Expires = DateTime.Now.AddDays(-1)
' storing the new cookie each time
Response.Cookies.Add(newCookie)
Next
It doesn't look like your creating all new cookies and adding them to the response properly.

Resources