|
-
Sep 1st, 2008, 01:22 PM
#1
Thread Starter
Frenzied Member
[2008] 2 if
Hi,
sorry I'm posting too much these times, but i need it to be fixed. i will do my best to follow this advice, maybe it's true. http://www.vbforums.com/showpost.php...46&postcount=6
thanks mendhack
Hi,
Well, now I have the same kind of code 2 times, but the 2nd one is not working. It was supposed to redirect to another page, but it'snot running the code i wrote until the end.
When irun the debug , it stops after this Do While reader2.Read()
Where could be the problem?
vb Code:
Dim Accesstring As String = ("SELECT FirstName, LastName, Email, StreetAddress, City, Country, State, Zip, Worknum, googlecheckout, paypal, csftcc, confirmationcode, paymentamount FROM dbo.reservation WHERE (confirmationcode = @concode)") Dim cmd3 As New SqlCommand(Accesstring, icnnn) cmd3.Parameters.Add("@concode", SqlDbType.NChar).Value = onlineconfirmationcode.Text Dim reader As SqlDataReader = cmd3.ExecuteReader '/paynow.html While reader.Read() afirstname = reader("FirstName").ToString() alastname = reader("LastName").ToString() aemail = reader("Email").ToString() aadress = reader("StreetAddress").ToString() acountry = reader("Country").ToString() acity = reader("City").ToString() astate = reader("State").ToString() azip = reader("Zip").ToString() aworknum = reader("Worknum").ToString() agooglecheckout = reader("googlecheckout").ToString apaypal = reader("paypal").ToString() acsftcc = reader("csftcc").ToString() aconfirmationcode = reader("confirmationcode").ToString() apaymentamount = reader("paymentamount").ToString() End While reader.Close() '------------------------------------------------- '----retrive payment link------------ Dim Accesstring2 As String = ("SELECT paymentamount, googlepaymentlink, paypalpaymentlink FROM settingss WHERE (paymentamount = N'" & apaymentamount & " ')") Dim writer As IO.TextWriter = New IO.StreamWriter("/paynoww.html") Dim cmd32 As New SqlCommand(Accesstring2, icnnn) Dim reader2 As SqlDataReader = cmd32.ExecuteReader Dim abcd As String '------For google checkout payment----------------------------------------------------------------- If agooglecheckout.Trim = "True" Then Do While reader2.Read() apaymentlink = reader2("googlepaymentlink").ToString() Response.Redirect(apaymentlink) statuss.Text = "You have just confirmed succefully your reservation!" Loop reader2.Close() End If '----------------------End of google------------------------------------------------------------------- '-----------------------For PayPal---------------------------------------------------- If apaypal.Trim = "True" Then Do While reader2.Read() apaymentlink = reader2("paypalpaymentlink").ToString() abcd = apaymentlink writer.WriteLine("<html><center><FORM ACTION=""https://www.paypal.com/cgi-bin/webscr"" METHOD=""POST""> <INPUT TYPE=""hidden"" NAME=""cmd"" VALUE=""_xclick""> <INPUT TYPE=""hidden"" NAME=""business"" VALUE=""xxxxxx""> <INPUT TYPE=""hidden"" NAME=""item_name"" VALUE=""Limousine transportation""> <INPUT TYPE=""hidden"" NAME=""amount"" VALUE="" " & abcd & " ""> <INPUT TYPE=""hidden"" NAME=""currency_code"" VALUE=""USD""> <INPUT TYPE=""hidden"" NAME=""first_name"" VALUE=""" & afirstname & """> <INPUT TYPE=""hidden"" NAME=""last_name"" VALUE=""" & alastname & """> <INPUT TYPE=""hidden"" NAME=""address1"" VALUE=""" & aadress & """> <INPUT TYPE=""hidden"" NAME=""city"" VALUE=""" & acity & """> <INPUT TYPE=""hidden"" NAME=""state"" VALUE=""" & astate & """> <INPUT TYPE=""hidden"" NAME=""zip"" VALUE=""" & azip & """> <INPUT TYPE=""hidden"" NAME=""lc"" VALUE=""US""> <INPUT TYPE=""hidden"" NAME=""email"" VALUE=""" & aemail & """> <INPUT TYPE=""hidden"" NAME=""night_phone_a"" VALUE=""" & aworknum & """> <INPUT TYPE=""image"" NAME=""submit"" BORDER=""0"" SRC=""http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif"" ALT=""PayPal - The safer, easier way to pay online""> <img alt="" border="" width=""1"" height=""1"" src=""https://www.paypal.com/en_US/i/scr/pixel.gif""> </FORM> </FORM></html>") writer.Close() Response.Redirect("c:/paynoww.html") Loop reader2.Close() End If End If
thank you
Last edited by met0555; May 26th, 2011 at 10:40 PM.
-
Sep 1st, 2008, 01:33 PM
#2
Re: [2008] 2 if
Why are you redirecting to a file on C? That will only work on your computer. When deployed into a real, live environment the redirect request will be sent via Http headers back to the user's web browser and then it will choke.
I'm not sure if that's your specific issue but it stood out to me and it's something that needs to be changed.
-
Sep 1st, 2008, 01:37 PM
#3
Thread Starter
Frenzied Member
Re: [2008] 2 if
Well, it's because i was trying it on a local server. no problem the main code have the correct links
-
Sep 1st, 2008, 01:42 PM
#4
Re: [2008] 2 if
You're closing your reader2 inside the while reader2 loop. It should be closed outside.
-
Sep 1st, 2008, 01:47 PM
#5
Thread Starter
Frenzied Member
Re: [2008] 2 if
Hi,
It worked like that for the google, but let me try it.
thanks
-
Sep 1st, 2008, 01:56 PM
#6
Thread Starter
Frenzied Member
Re: [2008] 2 if
Still, not working after making the change you asked.
-
Sep 1st, 2008, 02:00 PM
#7
Re: [2008] 2 if
How and when are agooglecheckout and apaypal being set? i.e. are they bit fields in the database? Something else? Why not use an actual boolean rather than a string?
Also, for some odd reason you're iterating through the reader and trying to redirect on every pass (which makes any reading you're attempting to do useless as it'll never be used). I would suggest changing this logic.
Have you ever used the debugger before? Set a breakpoint at the beginning of your code and step through it. The debugger will show you exactly what it's doing and what all of the values are at each step. Using this would solve most, if not all, of your latest posts and it's a valuable tool.
-
Sep 1st, 2008, 02:06 PM
#8
Thread Starter
Frenzied Member
Re: [2008] 2 if
They are bit.
I know about debug
>>>>>>>>>>>>>>>>>>When irun the debugger , it stops after this Do While reader2.Read()<<<<<<<<<<<<<<<<<<<<<<<<<,,
-
Sep 1st, 2008, 02:42 PM
#9
Re: [2008] 2 if
If it stops then does it redirect? Does it throw an exception? The debugger helps you go through the changes happening in your code live and should hopefully help you debug this type of problem.
-
Sep 1st, 2008, 08:32 PM
#10
Thread Starter
Frenzied Member
Re: [2008] 2 if
no it don't after that line it will go to the current code.
-
Sep 1st, 2008, 08:56 PM
#11
Re: [2008] 2 if
 Originally Posted by met0555
no it don't after that line it will go to the current code.
What does this mean? Isn't the code you're already debugging "current code"? I asked a couple of questions so which one does the "no" answer?
-
Sep 2nd, 2008, 01:46 AM
#12
Re: [2008] 2 if
Let's see the new, modified code.
Keep in mind that the paypal block won't work because you've already looped through reader2 for 'agooglecheckout'.
-
Sep 2nd, 2008, 02:38 AM
#13
Thread Starter
Frenzied Member
Re: [2008] 2 if
my modified code looks like my first post(updated).
i tried to use new reader ... for the paypal but same problem
thx
-
Sep 2nd, 2008, 05:20 AM
#14
Re: [2008] 2 if
Yes, let's see the code with the new reader. Because if you close reader2, you can't use it in the next loop.
-
Sep 2nd, 2008, 05:23 AM
#15
Thread Starter
Frenzied Member
Re: [2008] 2 if
vb Code:
'-- retrive data--- Dim Accesstring As String = ("SELECT FirstName, LastName, Email, StreetAddress, City, Country, State, Zip, Worknum, googlecheckout, paypal, csftcc, confirmationcode, paymentamount FROM dbo.reservation WHERE (confirmationcode = @concode)") Dim cmd3 As New SqlCommand(Accesstring, icnnn) cmd3.Parameters.Add("@concode", SqlDbType.NChar).Value = onlineconfirmationcode.Text Dim reader As SqlDataReader = cmd3.ExecuteReader '/paynow.html While reader.Read() afirstname = reader("FirstName").ToString() alastname = reader("LastName").ToString() aemail = reader("Email").ToString() aadress = reader("StreetAddress").ToString() acountry = reader("Country").ToString() acity = reader("City").ToString() astate = reader("State").ToString() azip = reader("Zip").ToString() aworknum = reader("Worknum").ToString() agooglecheckout = reader("googlecheckout").ToString apaypal = reader("paypal").ToString() acsftcc = reader("csftcc").ToString() aconfirmationcode = reader("confirmationcode").ToString() apaymentamount = reader("paymentamount").ToString() End While reader.Close() '------------------------------------------------- '----retrive payment link------------ Dim Accesstring2 As String = ("SELECT paymentamount, googlepaymentlink, paypalpaymentlink FROM settingss WHERE (paymentamount = N'" & apaymentamount & " ')") Dim Accesstring22 As String = ("SELECT paymentamount, googlepaymentlink, paypalpaymentlink FROM settingss WHERE (paymentamount = N'" & apaymentamount & " ')") Dim writer As IO.TextWriter = New IO.StreamWriter("/ppaynow.html") Dim cmd32 As New SqlCommand(Accesstring2, icnnn) Dim cmd322 As New SqlCommand(Accesstring2, icnnn2) Dim reader2 As SqlDataReader = cmd32.ExecuteReader Dim abcd As String '------For google checkout payment----------------------------------------------------------------- If agooglecheckout.Trim = "True" Then ' cmd32.Parameters.Add("@paymentamount", SqlDbType.NChar).Value = apaymentamount.ToString Do While reader2.Read() apaymentlink = reader2("googlepaymentlink").ToString() Response.Redirect(apaymentlink) statuss.Text = "You have just confirmed succefully your reservation!" Loop reader2.Close() End If '----------------------End of google------------------------------------------------------------------- '-----------------------For PayPal---------------------------------------------------- If apaypal.Trim = "True" Then Dim reader22 As SqlDataReader = cmd322.ExecuteReader Do While reader22.Read() apaymentlink = reader22("paypalpaymentlink").ToString() abcd = apaymentlink writer.WriteLine("<html><center><FORM ACTION=""https://www.paypal.com/cgi-bin/webscr"" METHOD=""POST""> <INPUT TYPE=""hidden"" NAME=""cmd"" VALUE=""_xclick""> <INPUT TYPE=""hidden"" NAME=""business"" VALUE=""xxxxxxxx""> <INPUT TYPE=""hidden"" NAME=""item_name"" VALUE=""Limousine transportation""> <INPUT TYPE=""hidden"" NAME=""amount"" VALUE="" " & abcd & " ""> <INPUT TYPE=""hidden"" NAME=""currency_code"" VALUE=""USD""> <INPUT TYPE=""hidden"" NAME=""first_name"" VALUE=""" & afirstname & """> <INPUT TYPE=""hidden"" NAME=""last_name"" VALUE=""" & alastname & """> <INPUT TYPE=""hidden"" NAME=""address1"" VALUE=""" & aadress & """> <INPUT TYPE=""hidden"" NAME=""city"" VALUE=""" & acity & """> <INPUT TYPE=""hidden"" NAME=""state"" VALUE=""" & astate & """> <INPUT TYPE=""hidden"" NAME=""zip"" VALUE=""" & azip & """> <INPUT TYPE=""hidden"" NAME=""lc"" VALUE=""US""> <INPUT TYPE=""hidden"" NAME=""email"" VALUE=""" & aemail & """> <INPUT TYPE=""hidden"" NAME=""night_phone_a"" VALUE=""" & aworknum & """> <INPUT TYPE=""image"" NAME=""submit"" BORDER=""0"" SRC=""http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif"" ALT=""PayPal - The safer, easier way to pay online""> <img alt="" border="" width=""1"" height=""1"" src=""https://www.paypal.com/en_US/i/scr/pixel.gif""> </FORM> </FORM></html>") writer.Close() Response.Redirect("/ppaynow.html") Loop reader22.Close() End If End If
Last edited by met0555; May 26th, 2011 at 10:39 PM.
-
Sep 2nd, 2008, 05:33 AM
#16
Re: [2008] 2 if
You really need to work on your variable and object naming schemes. 
And your logic, because I just noticed this:
Response.Redirect(apaymentlink)
in your second loop. This means that as soon as the response.redirect is hit, it'll head over to the target page. Of course it won't execute anything after it.
-
Sep 2nd, 2008, 05:47 AM
#17
Thread Starter
Frenzied Member
Re: [2008] 2 if
Well, now it started saying page not found, after do while reader22.
From what i see, itskips what is between loop, and dothe code after the loop
-
Sep 2nd, 2008, 06:58 AM
#18
Thread Starter
Frenzied Member
Re: [2008] 2 if
or is there another way to make work this
apaymentlink = reader2("googlepaymentlink").ToString()
without using reader, or using with different method?
-
Sep 2nd, 2008, 07:36 AM
#19
Re: [2008] 2 if
Use a dataset.
apaymentlink = ds.Tables(0).Rows(0)("googlepaymentlink").ToString()
And you don't need loops for it.
-
Sep 2nd, 2008, 08:08 AM
#20
Thread Starter
Frenzied Member
Re: [2008] 2 if
ok, well now this error There is no row at position 0. i tried with 1 but still the same. How can i fix it
da.Fill(ds)
Dim ds As New DataSet()
Dim da As New SqlDataAdapter(("SELECT paymentamount, googlepaymentlink, paypalpaymentlink FROM settingss WHERE (paymentamount = N'" & apaymentamount & " ')"), "Data Source=sdfsddsfsf;Initial Catalog=sdfsfsfsdf;Persist Security Info=True;User ID=sdfs;Password=sdfsdfsdfsfdsf")
-
Sep 2nd, 2008, 08:43 AM
#21
Re: [2008] 2 if
From error seems you dataset is emty,make sure some records are getting return for above query.
__________________
Rate the posts that helped you 
-
Sep 2nd, 2008, 09:16 AM
#22
Thread Starter
Frenzied Member
Re: [2008] 2 if
the query is working ok on SQL, but how can i check if the dataset contains data?
thx
-
Sep 2nd, 2008, 09:23 AM
#23
Re: [2008] 2 if
check if value of ds.Tables(0).Rows.count is greater than 0 or not?
__________________
Rate the posts that helped you 
-
Sep 2nd, 2008, 09:25 AM
#24
Re: [2008] 2 if
also it will be good if you can post you code to show us how you are filling your Dataset,and if it's same as that of Post #20 than make sure you are calling da.Fill(ds) after declaring da and not before that.
__________________
Rate the posts that helped you 
-
Sep 3rd, 2008, 04:13 PM
#25
Re: [2008] 2 if
ds.Tables(0) is not null and/or ds.Tables.Count > 0 and/or ds.Tables(0).Rows.Count > 0
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|