How to upload excel sheet (.xlxs) to sql server 2012 with vb.net and asp.net
-
Hello All, It is my first time that am posting a question here. I have research a lot on the web on how to upload excel sheet (.xlxs) to sql server 2012 database through asp.net and vb.net, however, unfortunately all those research was of no use. can someone please help me with the source code. thanks.
-
Hello All, It is my first time that am posting a question here. I have research a lot on the web on how to upload excel sheet (.xlxs) to sql server 2012 database through asp.net and vb.net, however, unfortunately all those research was of no use. can someone please help me with the source code. thanks.
If your research was of no use what makes you think anything we say here will be of use to you? We are not a code-writing service. This article should get you started - Upload and Download Files with SQL Server in ASP.NET[^] If you have a specific question after trying this by all means come back with the code you are having a problem with
-
Hello All, It is my first time that am posting a question here. I have research a lot on the web on how to upload excel sheet (.xlxs) to sql server 2012 database through asp.net and vb.net, however, unfortunately all those research was of no use. can someone please help me with the source code. thanks.
-
Hello All, It is my first time that am posting a question here. I have research a lot on the web on how to upload excel sheet (.xlxs) to sql server 2012 database through asp.net and vb.net, however, unfortunately all those research was of no use. can someone please help me with the source code. thanks.
Use fileupload control and on submit button call below function and save the data in db in binary format. Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs) ' Read the file and convert it to Byte Array Dim filePath As String = FileUpload1.PostedFile.FileName Dim filename As String = Path.GetFileName(filePath) Dim ext As String = Path.GetExtension(filename) Dim contenttype As String = String.Empty 'Set the contenttype based on File Extension Select Case ext Case ".doc" contenttype = "application/vnd.ms-word" Exit Select Case ".docx" contenttype = "application/vnd.ms-word" Exit Select Case ".xls" contenttype = "application/vnd.ms-excel" Exit Select Case ".xlsx" contenttype = "application/vnd.ms-excel" Exit Select Case ".jpg" contenttype = "image/jpg" Exit Select Case ".png" contenttype = "image/png" Exit Select Case ".gif" contenttype = "image/gif" Exit Select Case ".pdf" contenttype = "application/pdf" Exit Select End Select If contenttype <> String.Empty Then Dim fs As Stream = FileUpload1.PostedFile.InputStream Dim br As New BinaryReader(fs) Dim bytes As Byte() = br.ReadBytes(fs.Length) 'insert the file into database Dim strQuery As String = "insert into tblFiles" _ & "(Name, ContentType, Data)" _ & " values (@Name, @ContentType, @Data)" Dim cmd As New SqlCommand(strQuery) cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = filename cmd.Parameters.Add("@ContentType", SqlDbType.VarChar).Value _ = contenttype cmd.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes InsertUpdateData(cmd) lblMessage.ForeColor = System.Drawing.Color.Green lblMessage.Text = "File Uploaded Successfully" Else lblMessage.ForeColor = System.Drawing.Color.Red lblMessage.Text = "File format not recognised." _ & " Upload Image/Word/PDF/Excel formats" End If End Sub