类型 'UploaderEventArgs' 未定义
Type 'UploaderEventArgs' is not defined
我尝试使用下面的代码使用 vb.net 命令按钮将文件上传到 sql 服务器 table。但是在单击构建时,UploaderEventArgs 出现错误。
类型 'UploaderEventArgs' 未定义。
Imports System.Data.SqlClient
Imports System.IO
Public Class Form1
Protected Sub UploadAttachments1_FileUploaded(ByVal sender As Object, ByVal args As UploaderEventArgs)
'set connection string
Dim connectionString As String = System.Configuration.ConfigurationSettings.AppSettings("ConnectionString")
' Read the file and convert it to Byte Array
Dim data() As Byte = New Byte((args.FileSize) - 1) {}
'get file extension
Dim extensioin As String = args.FileName.Substring((args.FileName.LastIndexOf(".") + 1))
Dim fileType As String = ""
'set the file type based on File Extension
Select Case (extensioin)
Case "doc"
fileType = "application/vnd.ms-word"
Case "docx"
fileType = "application/vnd.ms-word"
Case "xls"
fileType = "application/vnd.ms-excel"
Case "xlsx"
fileType = "application/vnd.ms-excel"
Case "jpg"
fileType = "image/jpg"
Case "png"
fileType = "image/png"
Case "gif"
fileType = "image/gif"
Case "pdf"
fileType = "application/pdf"
End Select
Dim stream As Stream = args.OpenStream
'read the file as stream
stream.Read(data, 0, data.Length)
Dim con As SqlConnection = New SqlConnection(connectionString)
Dim com As SqlCommand = New SqlCommand
com.Connection = con
'set parameters
Dim p1 As SqlParameter = New SqlParameter("@Name", SqlDbType.VarChar)
Dim p2 As SqlParameter = New SqlParameter("@FileType", SqlDbType.VarChar)
Dim p3 As SqlParameter = New SqlParameter("@Data", SqlDbType.VarBinary)
p1.Value = args.FileName
p2.Value = fileType
p3.Value = data
com.Parameters.Add(p1)
com.Parameters.Add(p2)
com.Parameters.Add(p3)
com.CommandText = "Insert into Files (Name,FileType,Data) VALUES (@Name,@FileType,@Data)"
con.Open()
'insert the file into database
com.ExecuteNonQuery()
con.Close()
End Sub
End Class
上述代码的来源Link:
http://ajaxuploader.com/h/Save-Files-to-Database-using-FileUpload-Control.htm
看起来 UploaderEventArgs
是您链接的公司提供的框架的一部分,因此您需要先下载并安装它。它不是常规 .NET 库的一部分。
我尝试使用下面的代码使用 vb.net 命令按钮将文件上传到 sql 服务器 table。但是在单击构建时,UploaderEventArgs 出现错误。
类型 'UploaderEventArgs' 未定义。
Imports System.Data.SqlClient
Imports System.IO
Public Class Form1
Protected Sub UploadAttachments1_FileUploaded(ByVal sender As Object, ByVal args As UploaderEventArgs)
'set connection string
Dim connectionString As String = System.Configuration.ConfigurationSettings.AppSettings("ConnectionString")
' Read the file and convert it to Byte Array
Dim data() As Byte = New Byte((args.FileSize) - 1) {}
'get file extension
Dim extensioin As String = args.FileName.Substring((args.FileName.LastIndexOf(".") + 1))
Dim fileType As String = ""
'set the file type based on File Extension
Select Case (extensioin)
Case "doc"
fileType = "application/vnd.ms-word"
Case "docx"
fileType = "application/vnd.ms-word"
Case "xls"
fileType = "application/vnd.ms-excel"
Case "xlsx"
fileType = "application/vnd.ms-excel"
Case "jpg"
fileType = "image/jpg"
Case "png"
fileType = "image/png"
Case "gif"
fileType = "image/gif"
Case "pdf"
fileType = "application/pdf"
End Select
Dim stream As Stream = args.OpenStream
'read the file as stream
stream.Read(data, 0, data.Length)
Dim con As SqlConnection = New SqlConnection(connectionString)
Dim com As SqlCommand = New SqlCommand
com.Connection = con
'set parameters
Dim p1 As SqlParameter = New SqlParameter("@Name", SqlDbType.VarChar)
Dim p2 As SqlParameter = New SqlParameter("@FileType", SqlDbType.VarChar)
Dim p3 As SqlParameter = New SqlParameter("@Data", SqlDbType.VarBinary)
p1.Value = args.FileName
p2.Value = fileType
p3.Value = data
com.Parameters.Add(p1)
com.Parameters.Add(p2)
com.Parameters.Add(p3)
com.CommandText = "Insert into Files (Name,FileType,Data) VALUES (@Name,@FileType,@Data)"
con.Open()
'insert the file into database
com.ExecuteNonQuery()
con.Close()
End Sub
End Class
上述代码的来源Link:
http://ajaxuploader.com/h/Save-Files-to-Database-using-FileUpload-Control.htm
看起来 UploaderEventArgs
是您链接的公司提供的框架的一部分,因此您需要先下载并安装它。它不是常规 .NET 库的一部分。