我有文件上傳和上傳鏈接按鈕和提交按鈕..所以當我選擇文件並點擊上傳然後文件名顯示在標籤中,當我再次點擊瀏覽文件和選擇文件並單擊上傳文件,然後重新命名標籤中保存如此意味着標籤即在vb.net中插入文檔名稱和文檔路徑
abc.docx
def.docx
多個文件名顯示..等等..
現在我嘗試將這些文件在數據庫中保存不同的記錄表示這些文件保存在數據庫表中,然後看起來像這樣
ID DocumentName DocumentPath
1 abc.docx /downloads/abc.docx
2 def.docx /files/def.docx
爲了這個,我試試這個 SP
alter procedure spupload_file
@DocumentName varchar(100),
@Doctype tinyint
as
insert into DocDownloads (DocumentID,DocumentName,DocType)
select (select max(DocumentID) from DocDownloads)+ROW_NUMBER() over(order by @DocumentName),@DocumentName,7
代碼
Protected Sub LinkButton1_Click(sender As Object, e As EventArgs) Handles LinkButton1.Click
uploadmultiple_file(fileUpEx.FileName)
End Sub
Public Sub uploadmultiple_file(filename As String)
If fileUpEx.HasFiles Then
For Each uploadedfile As HttpPostedFile In fileUpEx.PostedFiles
'Label4.Text = ("<b>File: </b>" + uploadedfile.FileName)
Label4.Text += String.Format("{0}<br />", uploadedfile.FileName)
Next
End If
End Sub
Protected Sub pb_Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pb_submit.Click
Dim strKeyName() As String = {"DocumentName", "DocType"}
Dim objKeyVal() As Object = {Label4.Text,7}
structDb = objDataSet.ExecSP("tbl", "spupload_file", strKeyName, objKeyVal)
If structDb.intCode = 0 Then
Label5.Text = structDb.strMessage
Label5.CssClass = "error"
Exit Sub
End If
End Sub
當我嘗試這...這顯示了在數據庫表中的記錄像
1 abc.docx<br />def.docx<br />
的地方我想要這樣
1 abc.docx
2 def.docx
索引超出了數組的範圍。
以及我如何插入文檔路徑
任何幫助嗎?
根據@Andy裏德 修訂
好,我試試這個
For Each file As HttpPostedFile In ListBox1.Items
Dim DocumentName As String = file.FileName
Dim strKeyName() As String = {"DocumentName", "DocType"}
Dim objKeyVal() As Object = {DocumentName, 7}
structDb = objDataSet.ExecSP("tbl", "spupload_file", strKeyName, objKeyVal)
Next
If structDb.intCode = 0 Then
Label5.Text = structDb.strMessage
Label5.CssClass = "error"
Exit Sub
End If
但這顯示錯誤
'' 類型發生在DecibelCRM的異常。 dll,但未在用戶代碼中處理 附加信息:無法轉換類型爲「System.Web.UI.WebControls」的對象。 ListItem'來鍵入'System.Web.HttpPostedFile'。
我嘗試你的解決方案,並試圖做與SP,但這顯示錯誤..請檢查我的問題中更新的代碼.. –
'objDataSet.ExecSP()'的代碼是什麼樣子? 在我的答案,我把:'objDataSet.DocDownloads.AddDocDownloadsRow(DocumentName,DocType)'...這應該做你想做的'spupload_file'做的不是嗎?它基本上使用DocumentName和DocType將新行插入到objDataSet的DocDownloads表中。 –