我目前正在学习在 asp.net 中编程,我正在写信寻求以下问题的帮助:
我正在尝试执行以下连接,但是当我单击浏览器中的连接按钮时,没有任何反应。
aspx.vb 代码:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class _Default
Inherits System.Web.UI.Page
' Public Sub Button1(ByVal sender As Object, ByVal e As System.EventArgs)
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim connectionString As String
Dim connection As SqlConnection
connectionString = ConfigurationManager.ConnectionStrings("SQLDbConnection").ToString
connection = New SqlConnection(connectionString)
Try
connection.Open()
Catch ex As Exception
MsgBox("Not working")
End Try
If connection.State = 1 Then
MsgBox(" working")
End If
End Sub
End Class
asp.net 代码:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
我尝试在 asp.net 代码中添加“Onclick =”submit”,但它一直出现错误。
非常感谢您的帮助。感谢您的时间和帮助。