Can someone help me get this sub to exit correctly?

Discussion in 'ASP .Net' started by Teep, Jun 25, 2004.

  1. Teep

    Teep Guest

    Where there is a duplicate invoice, I want to stop the process and
    post to the user on the same page and not continue to the next
    page...I tried Return or Exit Sub...but still the same thing occurs.

    Sub Close1Open2(Source as Object, E as EventArgs)
    pnl1.visible="false"
    pnl2.visible="false"
    pnl3.visible="false"
    pnl4.visible="true"

    Dim strConn as string =
    "server=abcd;database=cds;trusted_connection=true"
    Dim MySQL as string = "Select supplier_cd, inv_no, inv_date from
    view_cds_all where supplier_cd='" & txtSupCD.text & "' and inv_no='" &
    txtInvNum.text & "' and inv_date='" & txtInvDate.text & "'"
    Dim MyConn as New SQLConnection(strConn)
    Dim objDR as SQLDataReader
    Dim Cmd as New SQLCommand(MySQL, MyConn)
    MyConn.Open()
    objDR=Cmd.ExecuteReader()
    While objDR.Read()
    If IsDbNull(objDR.GetString(0))=False Then
    blHasRows="True"
    else
    blHasRows="False"
    End If
    End While
    MyConn.Close()

    MySQL = "Insert into a_p.dbo.tbl_ap_web_ce_inv_terms (splr_cd,
    inv_numb, inv_dat) Values ('" & txtSupCD.text & "','" & txtInvNum.text
    & "'," & txtInvDate.text & ")"
    Dim Cmd2 as New SQLCommand(MySQL, MyConn)
    if blHasRows="False" then
    MyConn.Open()
    Cmd2.ExecuteNonQuery()
    lblResults.text="Your information has been received!"
    MyConn.Close
    else
    lblResults.text="Sorry, that information is already in the
    database"
    End If
    End Sub
     
    Teep, Jun 25, 2004
    #1
    1. Advertising

  2. Teep

    Rick Spiewak Guest

    You aren't showing the code that redirects to the next page, which is where
    you would need to detect and act on the difference. If you're calling this
    sub from that code, try making it a function and return a boolean indicating
    whether to continue or not.

    "Teep" <> wrote in message
    news:...
    > Where there is a duplicate invoice, I want to stop the process and
    > post to the user on the same page and not continue to the next
    > page...I tried Return or Exit Sub...but still the same thing occurs.
    >
    > Sub Close1Open2(Source as Object, E as EventArgs)
    > pnl1.visible="false"
    > pnl2.visible="false"
    > pnl3.visible="false"
    > pnl4.visible="true"
    >
    > Dim strConn as string =
    > "server=abcd;database=cds;trusted_connection=true"
    > Dim MySQL as string = "Select supplier_cd, inv_no, inv_date from
    > view_cds_all where supplier_cd='" & txtSupCD.text & "' and inv_no='" &
    > txtInvNum.text & "' and inv_date='" & txtInvDate.text & "'"
    > Dim MyConn as New SQLConnection(strConn)
    > Dim objDR as SQLDataReader
    > Dim Cmd as New SQLCommand(MySQL, MyConn)
    > MyConn.Open()
    > objDR=Cmd.ExecuteReader()
    > While objDR.Read()
    > If IsDbNull(objDR.GetString(0))=False Then
    > blHasRows="True"
    > else
    > blHasRows="False"
    > End If
    > End While
    > MyConn.Close()
    >
    > MySQL = "Insert into a_p.dbo.tbl_ap_web_ce_inv_terms (splr_cd,
    > inv_numb, inv_dat) Values ('" & txtSupCD.text & "','" & txtInvNum.text
    > & "'," & txtInvDate.text & ")"
    > Dim Cmd2 as New SQLCommand(MySQL, MyConn)
    > if blHasRows="False" then
    > MyConn.Open()
    > Cmd2.ExecuteNonQuery()
    > lblResults.text="Your information has been received!"
    > MyConn.Close
    > else
    > lblResults.text="Sorry, that information is already in the
    > database"
    > End If
    > End Sub
     
    Rick Spiewak, Jun 27, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. loga123
    Replies:
    2
    Views:
    350
    loga123
    May 20, 2006
  2. Yujo
    Replies:
    2
    Views:
    439
    Gabriel Genellina
    Apr 10, 2007
  3. Ben
    Replies:
    2
    Views:
    954
  4. chad
    Replies:
    14
    Views:
    607
    Arnaud Delobelle
    Oct 13, 2010
  5. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    2,166
    Lawrence D'Oliveiro
    May 20, 2011
Loading...

Share This Page