hi...use this simply put this code on button click
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Label2.Visible = True
Dim filePath As String = FileUpload1.PostedFile.FileName
Dim filename1 As String = Path.GetFileName(filePath)
Dim ext As String = Path.GetExtension(filename1)
Dim type As String = [String].Empty
If FileUpload1.HasFile Then
Try
Select Case ext
Case ".xls"
type = "application/vnd.ms-excel"
Exit Select
Case ".txt"
type = "application/vnd.txt"
Exit Select
End Select
If type <> [String].Empty Then
connection()
Dim fs As Stream = FileUpload1.PostedFile.InputStream
Dim br As New BinaryReader(fs)
Dim bytes As [Byte]() = br.ReadBytes(CType(fs.Length, Int32))
query = "insert into Excelfiledemo(Name,type,data)" & " values (@Name, @type, @Data)"
com = New SqlCommand(query, con)
com.Parameters.Add("@Name", SqlDbType.VarChar).Value = filename1
com.Parameters.Add("@type", SqlDbType.VarChar).Value = type
com.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes
com.ExecuteNonQuery()
Label2.ForeColor = System.Drawing.Color.Green
Label2.Text = "File Uploaded Successfully"
Else
Label2.ForeColor = System.Drawing.Color.Red
Label2.Text = "Select Only Excel and text Files "
End If
Catch ex As Exception
Label2.Text = "Error: " & ex.Message.ToString()
End Try
End If
End Sub
i hope this helps you...