多附件上传怎么添加到数据库中啊(VB的 在线)
想实现一个多附件上传功能 在网上找到的例子Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyTitle.Text = "<h3>多文件上传</h3>"
Upload.Text = "开始上传"
If (Me.IsPostBack) Then Me.SaveImages()
End Sub
Private Function SaveImages() As System.Boolean
'遍历File表单元素
Dim files As System.Web.HttpFileCollection = System.Web.HttpContext.Current.Request.Files
'状态信息
Dim strMsg As New System.Text.StringBuilder("上传的文件分别是:<hr color=red>")
Dim iFile As System.Int32
Try
For iFile = 0 To files.Count - 1
'检查文件扩展名字
Dim postedFile As System.Web.HttpPostedFile = files(iFile)
Dim fileName, fileExtension As System.String
fileName = System.IO.Path.GetFileName(postedFile.FileName)
If Not (fileName = String.Empty) Then
fileExtension = System.IO.Path.GetExtension(fileName)
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>")
strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>")
strMsg.Append("上传文件的文件名:" + fileName + "<br>")
strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>")
'可根据扩展名字的不同保存到不同的文件夹
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName)
End If
Next
strStatus.Text = strMsg.ToString()
Return True
Catch Ex As System.Exception
strStatus.Text = Ex.Message
Return False
End Try
End Function
End Class
请问我怎么把他的名字添加到数据库中啊
Dim myconn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Dim str_insert As String = "insert into [ce](user_id,xinxi,pic,content,users) VALUES (@user_id,@xinxi,@pic,@content,@users)"
Dim mycmd As SqlCommand = New SqlCommand(str_insert, myconn)
mycmd.Parameters.Add("@user_id", Trim(item.Value))
mycmd.Parameters.Add("@xinxi", Trim(xinxi.Text))
mycmd.Parameters.Add(New SqlParameter("@content", SqlDbType.NText, 10000))
mycmd.Parameters("@content").Value = FreeTextBox.Text
mycmd.Parameters.Add("@pic", 32)
mycmd.Parameters.Add("@users", my_user)
myconn.Open()
mycmd.ExecuteNonQuery()
myconn.Close()
HttpContext.Current.Response.Write("<script Language='javascript'>window.alert('操作成功');window.location.href = 'iss.aspx';</script>")
还有什么好方法大家可以告诉我下 --------------------编程问答-------------------- fileName 是文件名 可是怎么添加啊mycmd.Parameters.Add("@pic", fileName) fileName未声明
上面这个Private Function SaveImages() As System.Boolean 又不是Button 怎么办啊 --------------------编程问答-------------------- 有人吗 --------------------编程问答-------------------- 用字符截取一下就行了
fileName=fileName.Substring(0, fileName.LastIndexOf(@"/"));--------------------编程问答-------------------- 或者
fileName=fileName.Substring(0, fileName.LastIndexOf(@"\"));--------------------编程问答-------------------- 添加进去了 可是这样的话只要有一个附件就会生成1条数据 怎么能在附件多的时候都在一个列里啊
补充:.NET技术 , ASP.NET