| | |
File Upload in MySQL Database with ASP
Please support our ASP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
try this one, if i understand well what you want:
•
•
•
•
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Public Sub Addfile(ByVal sender As Object, ByVal e As EventArgs)
UploadFile(1, "test", 123, "c:\myfile.jpg")
End Sub
Public Shared Sub UploadFile(ByVal file_id As Integer, ByVal file_name As String, ByVal file_size As Integer, ByVal file_path As String)
Dim Conn As Data.Odbc.OdbcConnection = New Data.Odbc.OdbcConnection("dsn=mydatabase")
Conn.Open()
Dim command As Data.Odbc.OdbcCommand = New Data.Odbc.OdbcCommand("INSERT INTO `files` set file_name=?, file_size=?, file=?")
Dim file() As Byte = GetFile(file_path)
command.Parameters.Add("?", Data.Odbc.OdbcType.VarChar).Value = file_name
command.Parameters.Add("?", Data.Odbc.OdbcType.Int).Value = file_size
command.Parameters.Add("?", Data.Odbc.OdbcType.Binary).Value = file
command.Connection = Conn
command.ExecuteNonQuery()
Conn.Close()
End Sub
Public Shared Function GetFile(ByVal file_Path As String) As Byte()
Dim stream As System.IO.FileStream = New System.IO.FileStream(file_Path, IO.FileMode.Open, IO.FileAccess.Read)
Dim reader As System.IO.BinaryReader = New System.IO.BinaryReader(stream)
Dim file() As Byte = reader.ReadBytes(stream.Length)
reader.Close()
stream.Close()
Return file
End Function
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="addfile"/>
</div>
</form>
</body>
</html>
![]() |
Similar Threads
- Upload a word file into mysql database (Java)
- retrieving image from mysql database using php (PHP)
- can i use mysql database with asp (ASP)
- Backing up a MySQL database (MySQL)
Other Threads in the ASP Forum
- Previous Thread: Will this work
- Next Thread: ASP XML - Help Needed ?
Views: 6488 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for ASP
archive asp asp.net aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection calendar changeable connection current database databaseconnection diagnostics dreamweaver excel fso html iis microsoft msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile query record searchbox selectoption server single specfic sqlserver sqlserverconnection toolkit update web webserver windows7





