Webサイトをプログラミングしています注-VisualStudio2010のVBのプロジェクトではなく、LINQデータベースが関連付けられています。ユーザーに名前、電子メール、パスワード、および必要な管理者レベルの入力を求めるユーザー登録ページが作成されています。写真を追加する機能もあります。これは、標準のasp:fileuploadコントロールを介して実装されます。現在は機能していません。ファイルを閲覧して、「登録」ボタンをクリックすると、すべてのユーザーの詳細がデータベースに追加されます。私がこれまでに持っているコードは以下の通りです。
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If IsPostBack Then
Dim UpPath As String
UpPath = "~/Uploads/"
Image1.Visible = True
Image1.ImageUrl = Session("ImagePath")
If Not Directory.Exists(UpPath) Then
Directory.CreateDirectory("C:\UploadedUserFiles\")
End If
End If
End Sub
Protected Sub btnRegister_Click(sender As Object, e As System.EventArgs) Handles btnRegister.Click
Dim savePath = "\Uploads\"
Dim appPath As String = Server.MapPath("~")
If (FileUPload1.HasFile) Then
Dim savePath2 As String = savePath & Session("currentuser") & "" & FileUPload1.FileName
FileUPload1.SaveAs(appPath & savePath2)
Session("ImagePath") = "." & savePath
End If
' variables to store the user's registration details
Dim username As String
Dim email As String
Dim password As String
Dim retypedPassword As String
' variables to store the user's selected roles
Dim productOwner As Boolean
Dim projectManager As Boolean
Dim scrumMaster As Boolean
Dim developer As Boolean
' populate variables with the values from the web page
username = txtUsername.Text
email = txtEmail.Text
password = txtPassword.Text
retypedPassword = txtRetypePassword.Text
' check which user roles have been selected
productOwner = checkProductOwner.Checked
projectManager = checkProjectManager.Checked
scrumMaster = checkScrumMaster.Checked
developer = checkDeveloper.Checked
' boolean to check if the entered details are valid
Dim isValid As Boolean
isValid = True
' check if the values entered by the user are valid
If _
String.IsNullOrEmpty(username) Or _
String.IsNullOrEmpty(email) Or _
String.IsNullOrEmpty(password) Or _
String.IsNullOrEmpty(retypedPassword) Or _
password <> retypedPassword Then
isValid = False
End If
' if the values are valid, then populate the USER table with the new user and the USER ROLES table
' with the roles they are allowed in any project that will be created
If isValid Then
' set up LINQ connection with database
Dim db As New AgileClassesDataContext()
' create a user to populate a row in the USER table
Dim user As New User With _
{.Name = username, _
.Password = password, _
.Email = email}
' add the new user to the USER table
db.Users.InsertOnSubmit(user)
' submit the changes to the database
Try
db.SubmitChanges()
Catch ex As Exception
Console.WriteLine(ex)
db.SubmitChanges()
End Try
現在、データベースで「FileUPload1」を宣言していません。これを追加しようとすると、「System.Web.UI.WebControls.FileUploadタイプをSystem.Data.Linq.Binaryに変換できません」というエラーが表示されるためです。これを回避するために何をすべきか。私が使用しているデータベーステーブルは次のとおりです。
ユーザー
-UserID(int、incrementing)-Name(nvarchar)-Password(nvarchar)-Email(nvarchar)-PhotoID(image)
どんな提案も素晴らしいでしょう。ありがとう