Run SQL on form button and output result on page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    Run SQL on form button and output result on page

    Hi,

    I have an asp page with a form.
    A user enters a serial number in a text box.

    I want to add a button next to the text box such as 'Check Serial' to
    run some SQL in the background to see if that serial exists in the
    table, and then output 'Serial found' or 'Serial Not Found' next to
    the text box, so the user can decide whether to continue with the
    form.


    Appreciate your help.



    Thanks


    David

  • Mike Brind

    #2
    Re: Run SQL on form button and output result on page


    "David" <davidgordon@sc ene-double.co.ukwro te in message
    news:1176480364 .542772.296270@ y5g2000hsa.goog legroups.com...
    Hi,
    >
    I have an asp page with a form.
    A user enters a serial number in a text box.
    >
    I want to add a button next to the text box such as 'Check Serial' to
    run some SQL in the background to see if that serial exists in the
    table, and then output 'Serial found' or 'Serial Not Found' next to
    the text box, so the user can decide whether to continue with the
    form.
    >
    Have a look at the xmlhttpobject in javascript: www.w3schools.com/ajax

    --
    Mike Brind


    Comment

    • xxshoexx@gmail.com

      #3
      Re: Run SQL on form button and output result on page

      Using VB and ADO I have stored proc that checks for a value and give
      the return value. And kicks off the event onBlur

      <SCRIPT LANGUAGE="vbscr ipt">
      Public Sub getID(id)
      Dim cn: Set cn = CreateObject("A DODB.Connection ")
      Dim cmd: Set cmd = CreateObject("A DODB.Command")
      Dim rs: Set rs = CreateObject("A DODB.Recordset" )

      'cn.Open "db.udl"
      cn.Open "Provider=SQLOL EDB.1;Password=[Password];Persist
      Security Info=True;User ID=[UserID];Initial Catalog=[Database];Data
      Source=[Server Name]"
      cn.CursorLocati on = 3
      cmd.ActiveConne ction = cn
      cmd.CommandType = 4

      cmd.CommandText = "[dbo].[View:GetID]"
      cmd.Parameters. Append (cmd.CreatePara meter ("@ID",3, 1, 0,
      Null ))
      cmd.Parameters. Item("@ID").Val ue = id
      rs.Open cmd

      If rs.RecordCount = 0 Then
      MsgBox id & " is not a valid ID.", vbOkOnly, "Error"
      document.all("W orkoutID").Valu e = ""
      document.all("W orkoutName").in nerHTML = ""
      Else
      document.all("W orkoutID").Valu e = id
      document.all("W orkoutName").in nerHTML =
      rs.Fields.Item( "Topic")

      End if
      End Sub
      </SCRIPT>


      <input name="WorkoutID " size="5" type="text"
      onblur="vbscrip t:getId(Workout ID.value)">


      Comment

      • Bob Barrows [MVP]

        #4
        Re: Run SQL on form button and output result on page

        xxshoexx@gmail. com wrote:
        Using VB and ADO I have stored proc that checks for a value and give
        the return value. And kicks off the event onBlur
        >
        <SCRIPT LANGUAGE="vbscr ipt">
        Public Sub getID(id)
        Dim cn: Set cn = CreateObject("A DODB.Connection ")
        Dim cmd: Set cmd = CreateObject("A DODB.Command")
        Dim rs: Set rs = CreateObject("A DODB.Recordset" )
        >
        'cn.Open "db.udl"
        cn.Open "Provider=SQLOL EDB.1;Password=[Password];Persist
        Security Info=True;User ID=[UserID];Initial Catalog=[Database];Data
        Source=[Server Name]"
        Dangerous! You do realize this is all visible to the user simply via
        View|Source ??

        --
        Microsoft MVP -- ASP/ASP.NET
        Please reply to the newsgroup. The email account listed in my From
        header is my spam trap, so I don't check it very often. You will get a
        quicker response by posting to the newsgroup.


        Comment

        • xxshoexx@gmail.com

          #5
          Re: Run SQL on form button and output result on page

          On Apr 20, 3:48 pm, "Bob Barrows [MVP]" <reb01...@NOyah oo.SPAMcom>
          wrote:
          xxsho...@gmail. com wrote:
          Using VB and ADO I have stored proc that checks for a value and give
          the return value. And kicks off the event onBlur
          >
          <SCRIPT LANGUAGE="vbscr ipt">
          Public Sub getID(id)
          Dim cn: Set cn = CreateObject("A DODB.Connection ")
          Dim cmd: Set cmd = CreateObject("A DODB.Command")
          Dim rs: Set rs = CreateObject("A DODB.Recordset" )
          >
          'cn.Open "db.udl"
          cn.Open "Provider=SQLOL EDB.1;Password=[Password];Persist
          Security Info=True;User ID=[UserID];Initial Catalog=[Database];Data
          Source=[Server Name]"
          >
          Dangerous! You do realize this is all visible to the user simply via
          View|Source ??
          >
          --
          Microsoft MVP -- ASP/ASP.NET
          Please reply to the newsgroup. The email account listed in my From
          header is my spam trap, so I don't check it very often. You will get a
          quicker response by posting to the newsgroup.
          not if you put it inside of server side tags

          Comment

          • xxshoexx@gmail.com

            #6
            Re: Run SQL on form button and output result on page

            On Apr 20, 3:48 pm, "Bob Barrows [MVP]" <reb01...@NOyah oo.SPAMcom>
            wrote:
            xxsho...@gmail. com wrote:
            Using VB and ADO I have stored proc that checks for a value and give
            the return value. And kicks off the event onBlur
            >
            <SCRIPT LANGUAGE="vbscr ipt">
            Public Sub getID(id)
            Dim cn: Set cn = CreateObject("A DODB.Connection ")
            Dim cmd: Set cmd = CreateObject("A DODB.Command")
            Dim rs: Set rs = CreateObject("A DODB.Recordset" )
            >
            'cn.Open "db.udl"
            cn.Open "Provider=SQLOL EDB.1;Password=[Password];Persist
            Security Info=True;User ID=[UserID];Initial Catalog=[Database];Data
            Source=[Server Name]"
            >
            Dangerous! You do realize this is all visible to the user simply via
            View|Source ??
            >
            --
            Microsoft MVP -- ASP/ASP.NET
            Please reply to the newsgroup. The email account listed in my From
            header is my spam trap, so I don't check it very often. You will get a
            quicker response by posting to the newsgroup

            Also can just do async calls with it.

            Comment

            • Bob Barrows [MVP]

              #7
              Re: Run SQL on form button and output result on page

              xxshoexx@gmail. com wrote:
              On Apr 20, 3:48 pm, "Bob Barrows [MVP]" <reb01...@NOyah oo.SPAMcom>
              wrote:
              >xxsho...@gmail .com wrote:
              >>Using VB and ADO I have stored proc that checks for a value and give
              >>the return value. And kicks off the event onBlur
              >>
              >><SCRIPT LANGUAGE="vbscr ipt">
              <snip>
              >Dangerous! You do realize this is all visible to the user simply via
              >View|Source ??
              <snip>
              not if you put it inside of server side tags
              But your example shows it in a client-side script element.
              At least now you are aware of the desirability to do this in server-side
              code,
              --
              Microsoft MVP - ASP/ASP.NET
              Please reply to the newsgroup. This email account is my spam trap so I
              don't check it very often. If you must reply off-line, then remove the
              "NO SPAM"


              Comment

              • Bob Barrows [MVP]

                #8
                Re: Run SQL on form button and output result on page

                xxshoexx@gmail. com wrote:
                >
                Also can just do async calls with it.
                And why is this relevant? If it is in client-side script, the user can see
                it, whether async calls are done with it or not.

                --
                Microsoft MVP - ASP/ASP.NET
                Please reply to the newsgroup. This email account is my spam trap so I
                don't check it very often. If you must reply off-line, then remove the
                "NO SPAM"


                Comment

                Working...