在更新面板中使用fileupload的代码 [英] code to use fileupload inside update panel
本文介绍了在更新面板中使用fileupload的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我已使用此代码上传文件,但我无法在数据库中获得结果。
Hi all,I have used this code to upload file, but I cannot get the result in Database.
Protected Sub btnsave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnsave.Click
If FileUpload1.PostedFile IsNot Nothing Then
Dim FileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
'Save files to disk
FileUpload1.SaveAs(Server.MapPath("~/images/" & FileName))
Dim CN As New SqlConnection("Server=pc5268;uid=sa;pwd=klo;database=MSK2DB")
Dim qry As String = "insert into tblFiles (QID, Question, QDetail, QFilePath, QFileName) values(@QID, @Question, @QDetail, @QFilePath, @QFileName)"
Dim SqlCom As New SqlCommand(qry, CN)
SqlCom.Parameters.Add(New SqlParameter("@QID", DirectCast(TextBox1.Text, Object)))
SqlCom.Parameters.Add(New SqlParameter("@Question", DirectCast(TextBox2.Text, Object)))
SqlCom.Parameters.Add(New SqlParameter("@QDetail", DirectCast(TextBox3.Text, Object)))
SqlCom.Parameters.AddWithValue("@QFilePath", "~/images/" & FileName)
SqlCom.Parameters.AddWithValue("@QFileName", FileName)
SqlCom.CommandType = CommandType.Text
SqlCom.Connection = CN
Try
CN.Open()
SqlCom.ExecuteNonQuery()
Catch ex As Exception
Response.Write(ex.Message)
Finally
CN.Close()
CN.Dispose()
End Try
End If
End Sub
源代码:
Source code:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server">
<asp:TextBox ID="TextBox2" runat="server">
<asp:TextBox ID="TextBox3" runat="server">
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnsave" runat="server" Text="Save All" Width="95px" />
任何人都可以帮助我吗?
Can any one help me?
推荐答案
我已经发布了C#的代码,你可以在VB中尝试相同的方式
I have posted the code of C# and can u try the same way in VB
ScriptManager _scriptMan = ScriptManager.GetCurrent(this);
_scriptMan.AsyncPostBackTimeout = 36000;
ScriptManager1.RegisterPostBackControl(Upload_button);
很久以前,我遇到过类似的事情。解决使用触发器
在ASP.Net AJAX UpdatePanel控件中使用FileUpload控件 [ ^ ]
Long time back, I have faced similar thing & solved usingTriggers
Using FileUpload Control inside ASP.Net AJAX UpdatePanel Control[^]
这篇关于在更新面板中使用fileupload的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文