asp.net を使用した Web サイト ログインの構築に関する YouTube ビデオを見つけました。問題は C# にありますが、プログラムを実行したときにそれを VB に変換していたところ、このエラーが発生しました。
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:
1. Add a "Debug=true" directive at the top of the file that generated the error. Example:
or:
2) Add the following section to the configuration file of your application:
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
これは、何かが C# にあることを意味しますが、それが何であるかを見つけることができません。これがコードです。
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class Registration
Inherits System.Web.UI.Page
Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click
Dim con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("RegconnectionString").ConnectionString)
con.Open()
Dim insCmd As String = "Insert into Registration (Username, Password, EmailAddress, FullName, Country) values (@UserName, @Password, @EmailAddress, @FullName, @Country)"
Dim InsertUser As SqlCommand = New SqlCommand(insCmd, con)
InsertUser.Parameters.AddWithValue("@UserName", TextBoxUN.Text)
InsertUser.Parameters.AddWithValue("@Password", TextBoxPass.Text)
InsertUser.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text)
InsertUser.Parameters.AddWithValue("@FullName", TextBoxFN.Text)
InsertUser.Parameters.AddWithValue("@Country", DropDownListCountry.SelectedItem.ToString())
Try
InsertUser.ExecuteNonQuery()
con.Close()
Response.Redirect("Login.aspx")
Catch ex As Exception
Response.Write("You have just launched a nuclear warhead and started WWIII seek shelter ASAP")
End Try
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (IsPostBack) Then
Dim con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("RegconnectionString").ConnectionString)
con.Open()
Dim cmdStr As String = "SELECT COUNT(*) FROM Registration WHERE UserName='" + TextBoxUN.Text + "'"
Dim userExist As SqlCommand = New SqlCommand(cmdStr, con)
Dim temp As Integer = Convert.ToInt32(userExist.ExecuteScalar().ToString())
con.Close()
If temp = 1 Then
Response.Write("Username already exist. Please choose another username")
End If
End If
End Sub
End Class
何か見かけたら教えてください。ありがとう!