Results 1 to 25 of 25

Thread: [2008] 2 if

  1. #1
    Frenzied Member met0555's Avatar
    Join Date
    Jul 06
    Posts
    1,325

    [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:
    1. 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)")
    2.             Dim cmd3 As New SqlCommand(Accesstring, icnnn)
    3.             cmd3.Parameters.Add("@concode", SqlDbType.NChar).Value = onlineconfirmationcode.Text
    4.  
    5.  
    6.             Dim reader As SqlDataReader = cmd3.ExecuteReader
    7.  
    8.             '/paynow.html
    9.  
    10.  
    11.             While reader.Read()
    12.                 afirstname = reader("FirstName").ToString()
    13.                 alastname = reader("LastName").ToString()
    14.                 aemail = reader("Email").ToString()
    15.                 aadress = reader("StreetAddress").ToString()
    16.                 acountry = reader("Country").ToString()
    17.                 acity = reader("City").ToString()
    18.                 astate = reader("State").ToString()
    19.                 azip = reader("Zip").ToString()
    20.                 aworknum = reader("Worknum").ToString()
    21.                 agooglecheckout = reader("googlecheckout").ToString
    22.                 apaypal = reader("paypal").ToString()
    23.                 acsftcc = reader("csftcc").ToString()
    24.                 aconfirmationcode = reader("confirmationcode").ToString()
    25.                 apaymentamount = reader("paymentamount").ToString()
    26.  
    27.  
    28.  
    29.  
    30.             End While
    31.  
    32.  
    33.             reader.Close()
    34.             '-------------------------------------------------
    35.  
    36.  
    37.             '----retrive payment link------------
    38.             Dim Accesstring2 As String = ("SELECT     paymentamount, googlepaymentlink, paypalpaymentlink FROM settingss WHERE (paymentamount = N'" & apaymentamount & " ')")
    39.             Dim writer As IO.TextWriter = New IO.StreamWriter("/paynoww.html")
    40.             Dim cmd32 As New SqlCommand(Accesstring2, icnnn)
    41.             Dim reader2 As SqlDataReader = cmd32.ExecuteReader
    42.             Dim abcd As String
    43.  
    44.  
    45.             '------For google checkout payment-----------------------------------------------------------------
    46.             If agooglecheckout.Trim = "True" Then
    47.  
    48.          
    49.                 Do While reader2.Read()
    50.                     apaymentlink = reader2("googlepaymentlink").ToString()
    51.                     Response.Redirect(apaymentlink)
    52.                     statuss.Text = "You have just confirmed succefully your reservation!"
    53.                    
    54.                 Loop
    55.  reader2.Close()
    56.  
    57.             End If
    58.  
    59.             '----------------------End of google-------------------------------------------------------------------
    60.  
    61.             '-----------------------For PayPal----------------------------------------------------
    62.             If apaypal.Trim = "True" Then
    63.                 Do While reader2.Read()
    64.                     apaymentlink = reader2("paypalpaymentlink").ToString()
    65.  
    66.                  
    67.  
    68.                     abcd = apaymentlink
    69.                     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>")
    70.                     writer.Close()
    71.                     Response.Redirect("c:/paynoww.html")
    72.                  
    73.                 Loop
    74.  
    75.   reader2.Close()
    76.             End If
    77.  
    78.         End If

    thank you
    Last edited by met0555; May 26th, 2011 at 10:40 PM.

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 03
    Location
    USA, Maryland
    Posts
    4,981

    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.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  3. #3
    Frenzied Member met0555's Avatar
    Join Date
    Jul 06
    Posts
    1,325

    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

  4. #4
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 02
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: [2008] 2 if

    You're closing your reader2 inside the while reader2 loop. It should be closed outside.

  5. #5
    Frenzied Member met0555's Avatar
    Join Date
    Jul 06
    Posts
    1,325

    Re: [2008] 2 if

    Hi,

    It worked like that for the google, but let me try it.

    thanks

  6. #6
    Frenzied Member met0555's Avatar
    Join Date
    Jul 06
    Posts
    1,325

    Re: [2008] 2 if

    Still, not working after making the change you asked.

  7. #7
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 03
    Location
    USA, Maryland
    Posts
    4,981

    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.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  8. #8
    Frenzied Member met0555's Avatar
    Join Date
    Jul 06
    Posts
    1,325

    Re: [2008] 2 if

    They are bit.
    I know about debug
    >>>>>>>>>>>>>>>>>>When irun the debugger , it stops after this Do While reader2.Read()<<<<<<<<<<<<<<<<<<<<<<<<<,,

  9. #9
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 03
    Location
    USA, Maryland
    Posts
    4,981

    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.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  10. #10
    Frenzied Member met0555's Avatar
    Join Date
    Jul 06
    Posts
    1,325

    Re: [2008] 2 if

    no it don't after that line it will go to the current code.

  11. #11
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 03
    Location
    USA, Maryland
    Posts
    4,981

    Re: [2008] 2 if

    Quote 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?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  12. #12
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 02
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    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'.

  13. #13
    Frenzied Member met0555's Avatar
    Join Date
    Jul 06
    Posts
    1,325

    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

  14. #14
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 02
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    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.

  15. #15
    Frenzied Member met0555's Avatar
    Join Date
    Jul 06
    Posts
    1,325

    Re: [2008] 2 if

    vb Code:
    1. '-- retrive data---
    2.  
    3.             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)")
    4.             Dim cmd3 As New SqlCommand(Accesstring, icnnn)
    5.             cmd3.Parameters.Add("@concode", SqlDbType.NChar).Value = onlineconfirmationcode.Text
    6.  
    7.  
    8.             Dim reader As SqlDataReader = cmd3.ExecuteReader
    9.  
    10.             '/paynow.html
    11.  
    12.  
    13.             While reader.Read()
    14.                 afirstname = reader("FirstName").ToString()
    15.                 alastname = reader("LastName").ToString()
    16.                 aemail = reader("Email").ToString()
    17.                 aadress = reader("StreetAddress").ToString()
    18.                 acountry = reader("Country").ToString()
    19.                 acity = reader("City").ToString()
    20.                 astate = reader("State").ToString()
    21.                 azip = reader("Zip").ToString()
    22.                 aworknum = reader("Worknum").ToString()
    23.                 agooglecheckout = reader("googlecheckout").ToString
    24.                 apaypal = reader("paypal").ToString()
    25.                 acsftcc = reader("csftcc").ToString()
    26.                 aconfirmationcode = reader("confirmationcode").ToString()
    27.                 apaymentamount = reader("paymentamount").ToString()
    28.  
    29.  
    30.  
    31.  
    32.             End While
    33.  
    34.  
    35.             reader.Close()
    36.             '-------------------------------------------------
    37.  
    38.  
    39.             '----retrive payment link------------
    40.             Dim Accesstring2 As String = ("SELECT     paymentamount, googlepaymentlink, paypalpaymentlink FROM settingss WHERE (paymentamount = N'" & apaymentamount & " ')")
    41.             Dim Accesstring22 As String = ("SELECT     paymentamount, googlepaymentlink, paypalpaymentlink FROM settingss WHERE (paymentamount = N'" & apaymentamount & " ')")
    42.  
    43.             Dim writer As IO.TextWriter = New IO.StreamWriter("/ppaynow.html")
    44.             Dim cmd32 As New SqlCommand(Accesstring2, icnnn)
    45.             Dim cmd322 As New SqlCommand(Accesstring2, icnnn2)
    46.  
    47.             Dim reader2 As SqlDataReader = cmd32.ExecuteReader
    48.  
    49.             Dim abcd As String
    50.             '------For google checkout payment-----------------------------------------------------------------
    51.             If agooglecheckout.Trim = "True" Then
    52.  
    53.                 ' cmd32.Parameters.Add("@paymentamount", SqlDbType.NChar).Value = apaymentamount.ToString
    54.                 Do While reader2.Read()
    55.                     apaymentlink = reader2("googlepaymentlink").ToString()
    56.                     Response.Redirect(apaymentlink)
    57.                     statuss.Text = "You have just confirmed succefully your reservation!"
    58.  
    59.                 Loop
    60.                 reader2.Close()
    61.                
    62.             End If
    63.             '----------------------End of google-------------------------------------------------------------------
    64.  
    65.             '-----------------------For PayPal----------------------------------------------------
    66.             If apaypal.Trim = "True" Then
    67.                 Dim reader22 As SqlDataReader = cmd322.ExecuteReader
    68.                 Do While reader22.Read()
    69.                     apaymentlink = reader22("paypalpaymentlink").ToString()
    70.                    
    71.  
    72.                     abcd = apaymentlink
    73.                     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>")
    74.                     writer.Close()
    75.                     Response.Redirect("/ppaynow.html")
    76.  
    77.                 Loop
    78.                 reader22.Close()
    79.  
    80.             End If
    81.  
    82.         End If
    Last edited by met0555; May 26th, 2011 at 10:39 PM.

  16. #16
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 02
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    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.

  17. #17
    Frenzied Member met0555's Avatar
    Join Date
    Jul 06
    Posts
    1,325

    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

  18. #18
    Frenzied Member met0555's Avatar
    Join Date
    Jul 06
    Posts
    1,325

    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?

  19. #19
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 02
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: [2008] 2 if

    Use a dataset.

    apaymentlink = ds.Tables(0).Rows(0)("googlepaymentlink").ToString()

    And you don't need loops for it.

  20. #20
    Frenzied Member met0555's Avatar
    Join Date
    Jul 06
    Posts
    1,325

    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")

  21. #21
    Frenzied Member
    Join Date
    Jan 06
    Posts
    1,827

    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

  22. #22
    Frenzied Member met0555's Avatar
    Join Date
    Jul 06
    Posts
    1,325

    Re: [2008] 2 if

    the query is working ok on SQL, but how can i check if the dataset contains data?

    thx

  23. #23
    Frenzied Member
    Join Date
    Jan 06
    Posts
    1,827

    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

  24. #24
    Frenzied Member
    Join Date
    Jan 06
    Posts
    1,827

    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

  25. #25
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 02
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    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
  •