Public Sub AddPerson(ByVal sender As Object, ByVal e As EventArgs)
Dim intImageSize As Int64
Dim strImageType As String
Dim ImageStream As Stream
Dim filepath As String
Dim filepart() As String
Dim filename As String
Dim getfolderpartabs As String
Dim endfilename As String
Dim file() As String ' 获得图片的大小
intImageSize = PersonImage.PostedFile.ContentLength
' 获得图片类型
strImageType = PersonImage.PostedFile.ContentType
'获取文件名
filepath = PersonImage.PostedFile.FileName
'以"\"为标志分割文件名并将各部分存入一个数组
filepart = Split(filepath, "\")
'获取不含路径的文件名
filename = filepart(filepart.Length - 1)
'得到文件扩展名
file = Split(filename, ".")
endfilename = file(file.Length - 1)
'获取文件将要上传的路径
getfolderpartabs = getfolderpath("files")
'保存上传附件到指定的文件夹
PersonImage.PostedFile.SaveAs(getfolderpartabs & "\" & filename) '读取图片
'ImageStream = PersonImage.PostedFile.InputStream
'Dim ImageContent(intImageSize) As Byte
'Dim intStatus As Integer
'intStatus = ImageStream.Read(ImageContent, 0, intImageSize)
' 创建Connection和Command对象
Dim strCnn As String = "data source=bhys;uid=sa;pwd=sa;database=test"
Dim myConnection As New SqlConnection(strCnn)
Dim myCommand As New SqlCommand("sp_person_isp", myConnection)
' 使用存储过程
myCommand.CommandType = CommandType.StoredProcedure
' 向存储过程添加参数
Dim prmEmail As New SqlParameter("@PersonEmail", SqlDbType.NVarChar, 255)
prmEmail.Value = txtPersonEmail.Text
myCommand.Parameters.Add(prmEmail) Dim prmName As New SqlParameter("@PersonName", SqlDbType.NVarChar, 255)
prmName.Value = txtPersonName.Text
myCommand.Parameters.Add(prmName)
Dim prmSex As New SqlParameter("@PersonSex", SqlDbType.Char, 1) If sexMale.Checked Then
prmSex.Value = "M"
Else
prmSex.Value = "F"
End If
myCommand.Parameters.Add(prmSex) Dim prmPersonDOB As New SqlParameter("@PersonDOB", SqlDbType.DateTime)
prmPersonDOB.Value = txtPersonDob.Text
myCommand.Parameters.Add(prmPersonDOB) Dim prmPersonImage As New SqlParameter("@PersonImage", SqlDbType.NVarChar)
prmPersonImage.Value = "files/" & filename
myCommand.Parameters.Add(prmPersonImage) Dim prmPersonImageType As New SqlParameter("@PersonImageType", SqlDbType.NVarChar, 255)
prmPersonImageType.Value = endfilename
myCommand.Parameters.Add(prmPersonImageType) Try
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
Response.Write("添加成功!")
Catch SQLexc As SqlException
Response.Write("添加失败,原因:" & SQLexc.ToString())
End Try
End Sub
Dim intImageSize As Int64
Dim strImageType As String
Dim ImageStream As Stream
Dim filepath As String
Dim filepart() As String
Dim filename As String
Dim getfolderpartabs As String
Dim endfilename As String
Dim file() As String ' 获得图片的大小
intImageSize = PersonImage.PostedFile.ContentLength
' 获得图片类型
strImageType = PersonImage.PostedFile.ContentType
'获取文件名
filepath = PersonImage.PostedFile.FileName
'以"\"为标志分割文件名并将各部分存入一个数组
filepart = Split(filepath, "\")
'获取不含路径的文件名
filename = filepart(filepart.Length - 1)
'得到文件扩展名
file = Split(filename, ".")
endfilename = file(file.Length - 1)
'获取文件将要上传的路径
getfolderpartabs = getfolderpath("files")
'保存上传附件到指定的文件夹
PersonImage.PostedFile.SaveAs(getfolderpartabs & "\" & filename) '读取图片
'ImageStream = PersonImage.PostedFile.InputStream
'Dim ImageContent(intImageSize) As Byte
'Dim intStatus As Integer
'intStatus = ImageStream.Read(ImageContent, 0, intImageSize)
' 创建Connection和Command对象
Dim strCnn As String = "data source=bhys;uid=sa;pwd=sa;database=test"
Dim myConnection As New SqlConnection(strCnn)
Dim myCommand As New SqlCommand("sp_person_isp", myConnection)
' 使用存储过程
myCommand.CommandType = CommandType.StoredProcedure
' 向存储过程添加参数
Dim prmEmail As New SqlParameter("@PersonEmail", SqlDbType.NVarChar, 255)
prmEmail.Value = txtPersonEmail.Text
myCommand.Parameters.Add(prmEmail) Dim prmName As New SqlParameter("@PersonName", SqlDbType.NVarChar, 255)
prmName.Value = txtPersonName.Text
myCommand.Parameters.Add(prmName)
Dim prmSex As New SqlParameter("@PersonSex", SqlDbType.Char, 1) If sexMale.Checked Then
prmSex.Value = "M"
Else
prmSex.Value = "F"
End If
myCommand.Parameters.Add(prmSex) Dim prmPersonDOB As New SqlParameter("@PersonDOB", SqlDbType.DateTime)
prmPersonDOB.Value = txtPersonDob.Text
myCommand.Parameters.Add(prmPersonDOB) Dim prmPersonImage As New SqlParameter("@PersonImage", SqlDbType.NVarChar)
prmPersonImage.Value = "files/" & filename
myCommand.Parameters.Add(prmPersonImage) Dim prmPersonImageType As New SqlParameter("@PersonImageType", SqlDbType.NVarChar, 255)
prmPersonImageType.Value = endfilename
myCommand.Parameters.Add(prmPersonImageType) Try
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
Response.Write("添加成功!")
Catch SQLexc As SqlException
Response.Write("添加失败,原因:" & SQLexc.ToString())
End Try
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货