在我的网页上单击按钮我运行一个sql语句,我也想运行一个Web请求。我不想从Web请求加载任何东西,jsut运行它。但这是有趣的事情。作为sql语句的代码运行jsut很好,然后它下面的其他所有东西似乎都没有运行....服务器永远不会收到Web请求。
如果我将代码复制到页面并只运行它的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
'开始的代码似乎没有运行 “这个代码单独运行在另一页上 '但是,即使是上面的代码, '我从来没有看到任何问题的结果
' 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