Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Two Questions - Get @@identity and pass to new page
Message
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Two Questions - Get @@identity and pass to new page
Divers
Thread ID:
00876853
Message ID:
00876853
Vues:
45
This is fun...I keep learning new things.

I have a page where the user can submit a simple change request. I've got writing the request to the database, but I need to provide the user the tracking ID (using and identity column for the ID). Once I get the ID, I want to show another page to let the user know the request sumitted ok, and here is there tracking ID, below is the code I have in a button on the page to save the request.

I'm not sure how to run the query in aspx to get the identity, and I'm sure I'm not calling the confirmation page in a way to pass a parameter. Thanks for any help
   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim myconnection As SqlConnection
        Dim mycommand As SqlCommand
        Dim myreader As SqlDataReader
        Dim sql As String
        Dim connStr As String
        Dim lcField1 As String
        Dim lcField2 As String
        Dim lcField3 As String
        lcField1 = Me.TextBox1.Text
        lcField2 = Me.TextBox2.Text
        lcField3 = Me.TextBox3.Text
        Dim lnConfirmationNumber As Integer


        sql = "insert into psr (facilityName,description,ProblemDef) values (" & lcField1 & "," & lcField2 & "," & lcField3 & ")"

        connStr = "Server=localhost;uid=sa;pwd=x12cqi;database=ctoreversions"

        myconnection = New SqlConnection(connStr)
        myconnection.Open()
        mycommand = New SqlCommand(sql, myconnection)
        Try
            mycommand.ExecuteNonQuery()
            ' Get the confirmation Number
            sql = "select @@identity as newID"
            ' Need some code here to run the query and return store the value to the variable

            ' Close Connection
            myconnection.Close()
            ' Show and display the confirmation page
            Response.Redirect("confirm.aspx")
        Catch ex As Exception
            Me.TextBox3.Text = ex.ToString & "Command = " & sql.ToString
        End Try


    End Sub
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform