1

在我的网页中单击按钮时,我运行一个 sql 语句,我还想运行一个 Web 请求。我不想从 Web 请求中加载任何内容,只需运行它。但有趣的是。sql语句的代码运行良好,然后它下面的所有其他东西似乎都没有运行.... 服务器永远不会收到网络请求。

如果我将代码复制到页面并仅运行它可以工作的 Web 请求代码。但在这里它没有。

ASP.NET。感谢大家。我难住了。

Imports System
Imports System.Data
Imports System.Web
Imports System.Data.SqlClient

Imports System.IO
Imports System.Net
Imports System.Text

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub btnAddDeckSize_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddDeckSize.Click
    If txtDeckSize.Text > "" And txtNewDeckPrice.Text > "" Then
        Dim WasError As Boolean = False
        Dim SQLstring As String = "Server=server;Database=SecondLifeDatabases;Integrated Security=true"
        Dim SQLconn As SqlConnection
        Dim SQLcmd As New SqlCommand()
        SQLconn = New SqlConnection(SQLstring)
        Try
            SQLconn.Open()
            SQLcmd.Connection = SQLconn
            Try
                SQLcmd.CommandText = ("INSERT INTO [SecondLifeDatabases].[dbo].[YuGiOh-DecksAndPrices]([DeckSize] ,[PriceInLindins])VALUES (" + txtDeckSize.Text + "," + txtNewDeckPrice.Text + ")")
                SQLcmd.ExecuteNonQuery()
            Catch ex As Exception
                Context.Response.Write("error:" + vbCrLf + " " + vbCrLf + "Unable to insert sql data, Type:" + vbCrLf + " " + vbCrLf + ex.Message)
                WasError = True
                SQLconn.Close()
            End Try
        Catch ex As Exception
            Context.Response.Write("error:" + vbCrLf + " " + vbCrLf + "Could not open database:" + vbCrLf + " " + vbCrLf + ex.Message)
            WasError = True
            SQLconn.Close()
        End Try
        SQLconn.Close()
        If WasError = False Then
            Context.Response.Redirect("~/YuGiOh.aspx")
        End If
    Else
        Context.Response.Write("Please check your values, something is Missing")
    End If

'开始代码似乎没有运行'此代码单独运行在另一页上'但在这里,即使上面的代码运行,'我从来没有看到代码 BLOW 的任何结果

    ' Create a request using a URL that can receive a post. 
    Dim request As WebRequest = WebRequest.Create("http://sim6103.agni.lindenlab.com:12046/cap/b936c974-cfab-c2ee-a184-4288fe0a10f8")
    ' Set the Method property of the request to POST.
    request.Method = "POST"
    ' Create POST data and convert it to a byte array.
    Dim postData As String = "This is a test that posts this string to a Web server."
    Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
    ' Set the ContentType property of the WebRequest.
    request.ContentType = "application/x-www-form-urlencoded"
    ' Set the ContentLength property of the WebRequest.
    request.ContentLength = byteArray.Length
    ' Get the request stream.
    Dim dataStream As Stream = request.GetRequestStream()
    ' Write the data to the request stream.
    dataStream.Write(byteArray, 0, byteArray.Length)
    ' Close the Stream object.
    dataStream.Close()
    ' Get the response.
    Dim response As WebResponse = request.GetResponse()
    ' Display the status.
    Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
    ' Get the stream containing content returned by the server.
    dataStream = response.GetResponseStream()
    ' Open the stream using a StreamReader for easy access.
    Dim reader As New StreamReader(dataStream)
    ' Read the content.
    Dim responseFromServer As String = reader.ReadToEnd()
    ' Display the content.
    Console.WriteLine(responseFromServer)
    ' Clean up the streams.
    reader.Close()
    dataStream.Close()
    response.Close()
End Sub
4

0 回答 0