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?