ユーザーが自分のプロフィール情報を編集できるプロフィール編集ページがあります。現時点では、「userprofiles」テーブルに対応するレコードがないため、新しいユーザーはこのページを使用できません。同じデータベース内の対応する aspnet_User テーブルで aspnet_ メンバーシップ システムを使用しています。「userprofiles」と aspnet テーブルの間にリンクはありません
テーブルにユーザーのレコードがあるかどうかを確認し、テキストボックスにプロファイル情報を表示する「DisplayData()」というサブがあります。残念ながら、新しいユーザーの場合、テーブルにレコードがないため、エラーがスローされます
これが私のPage_Loadサブです:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Session("userName") = User.Identity.Name
Dim conn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("BookMeetConnString").ConnectionString)
conn.Open()
Dim cmdcheck As New OleDbCommand("SELECT TravellerName FROM userprofiles WHERE (TravellerName = ?) ", conn)
cmdcheck.Parameters.AddWithValue("@userName", Session("userName"))
Dim profileCheckDr = cmdcheck.ExecuteReader()
If IsDBNull(profileCheckDr("TravellerName")) Then
??
End If
If Not IsPostBack Then
DisplayData()
savec.Visible = False
End If
End Sub
そして、現在のすべてのユーザー プロファイル情報をページのテキスト ボックスに入力する DisplayData() 関数を次に示します。
Protected Sub DisplayData()
Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("BookMeetConnString").ConnectionString)
Dim sql = "SELECT * FROM userprofiles WHERE TravellerName=@f1"
Dim cmd = New OleDbCommand(sql, conn)
cmd.Parameters.AddWithValue("@f1", User.Identity.Name)
conn.Open()
Dim profileDr = cmd.ExecuteReader()
profileDr.Read()
Dim newEmailAddress = ""
Dim newDescription = ""
Dim newDOB = ""
Dim newLocation = ""
Dim newProfession = ""
Dim newSmoker = ""
Dim newDrinker = ""
Dim newEducationLevel = ""
Dim newMaritalStatus = ""
If Not IsDBNull(profileDr("AvatarURL")) Then ProfilePic.ImageUrl = profileDr.Item("AvatarURL")
If Not IsDBNull(profileDr("EmailAddress")) Then newEmailAddress = profileDr.Item("EmailAddress")
If Not IsDBNull(profileDr("DOB")) Then newDOB = profileDr.Item("DOB")
If Not IsDBNull(profileDr("Location")) Then newLocation = profileDr.Item("Location")
If Not IsDBNull(profileDr("Description")) Then newDescription = profileDr.Item("Description")
If Not IsDBNull(profileDr("Profession")) Then newProfession = profileDr.Item("Profession")
If Not IsDBNull(profileDr("Smoker")) Then newSmoker = profileDr.Item("Smoker")
If Not IsDBNull(profileDr("Drinker")) Then newDrinker = profileDr.Item("Drinker")
If Not IsDBNull(profileDr("EducationLevel")) Then newEducationLevel = profileDr.Item("EducationLevel")
If Not IsDBNull(profileDr("MaritalStatus")) Then newMaritalStatus = profileDr.Item("MaritalStatus")
If Not IsDBNull(profileDr("AvatarURL")) Then ProfilePic.ImageUrl = profileDr.Item("AvatarURL")
description.Text = newDescription
email.Text = newEmailAddress
smoker.SelectedValue = newSmoker
drinker.SelectedValue = newDrinker
dd_userlocation.SelectedValue = newLocation
dob.Text = newDOB
educationlevel.SelectedValue = newEducationLevel
profession.SelectedValue = newProfession
maritalstatus.SelectedValue = newMaritalStatus
conn.Close()
End Sub
Page Load サブでクエリの結果が何も返されない場合に DisplayData() サブが実行されないように、Page Load サブから抜け出すにはどうすればよいですか。既に「Exit Sub」を使用してみましたが、うまくいかないようです。