웹 사이트를 프로그래밍하고 있습니다. 참고 - Visual Studio 2010의 VB에서 프로젝트에 VB를 사용하고 LINQ 데이터베이스를 연결해야합니다. 사용자 등록 페이지가 있습니다. 그들의 이름, 전자 메일, 암호 및 관리자 수준이 필요합니다. 또한 사진을 추가하는 기능입니다. 이것은 표준 asp : fileupload 컨트롤을 통해 구현됩니다. 현재 작동하지 않습니다. 파일을 찾아보고 싶으면 모든 사용자 세부 정보를 "등록"버튼을 클릭하여 데이터베이스에 추가하십시오. 지금까지 가지고있는 코드는 아래와 같습니다. 내가 그것을 추가하려고 할 때마다 나는 오류가 "System.Data.Linq에 converet 형 System.Web.UI.WebControls.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'선언하지 않았습니다. 바이너리 "나는 이것을 피하기 위해 무엇을해야할지 모른다. 내가 사용하고 데이터베이스 테이블은 다음과 같습니다
사용자
-userid (INT, 증가) -Name (NVARCHAR) -Password (NVARCHAR) - 이메일 (NVARCHAR) -PhotoID (이미지)
어떤 제안이 좋을 것입니다. 감사합니다.
안녕 감사합니다.불행하게도, 이것이 특정 하드웨어 위치를 보장 할 수 없기 때문에 uni 서버에서 호스팅되는 대학 프로젝트이므로 나에게 직접적인 문제는 아닙니다. 반면 이미지 (소량)가 데이터베이스에 보관되어 있으면 패키징 할 수 있습니다 모두 함께 호스트하고 – Gavin
파일을 저장하는 유일한 방법이 데이터베이스이고 SQL Server 2008 이상을 사용하는 경우 변수 유형 "이미지"를 지원합니다. 사진을이 유형의 데이터베이스로 저장할 수 있습니다. –
나는 이미 데이터베이스에 선언 된 이미지 필드를 가지고 있지만 실제로 이미지를 업로드하는 방법을 모른다. 언급했듯이 LINQ를 사용하고 있습니다. 문제의 전체 범위는 등록 페이지 (위의 코드)입니다. 사용자는 이름 : - 이름, 이메일, 비밀번호, 관리자 수준을 입력하고 사진을 찾아보고 업로드 할 수 있어야합니다. 하나의 제출 버튼으로 모든 이벤트를 처리하기를 원합니다. FileUpload 컨트롤을 제출 단추에 연결하여 모든 데이터를한데 모아서 한 명의 사용자로 입력하는 방법을 모르겠습니다. – Gavin