LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Insert a file ito sql-database via Excel wo filestream

Hi,

i try to insert a file (*.pdf) wich is referenced in an xl-sheet into a sql
database.
the required fileformat is blob.

I found the following code for doing this in VB.

Is there anything that can do the same in excel (like here the filestream)

THX for any help

Nobby

Dim conn As New MySqlConnection
Dim cmd As New MySqlCommand

Dim SQL As String

Dim FileSize As UInt32
Dim rawData() As Byte
Dim fs As FileStream

conn.ConnectionString = "server=127.0.0.1;" _
& "uid=root;" _
& "pwd=12345;" _
& "database=test"

Try
fs = New FileStream("c:\image.png", FileMode.Open, FileAccess.Read)
FileSize = fs.Length

rawData = New Byte(FileSize) {}
fs.Read(rawData, 0, FileSize)
fs.Close()

conn.Open()

SQL = "INSERT INTO file VALUES(NULL, ?FileName, ?FileSize, ?File)"

cmd.Connection = conn
cmd.CommandText = SQL
cmd.Parameters.Add("?FileName", strFileName)
cmd.Parameters.Add("?FileSize", FileSize)
cmd.Parameters.Add("?File", rawData)

cmd.ExecuteNonQuery()

MessageBox.Show("File Inserted into database successfully!", _
"Success!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)

conn.Close()
Catch ex As Exception
MessageBox.Show("There was an error: " & ex.Message, "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to handle database insert, update and select in excel? anders123 Excel Worksheet Functions 0 May 23rd 08 03:20 PM
How to insert Excel sheet to a DB2 database fandecine Excel Programming 1 August 15th 05 09:31 PM
Insert record into Excel database using a custom VBA form? [email protected] Excel Programming 3 July 31st 05 03:54 AM
Open a workbook in the background (like filestream) TommySzalapski[_8_] Excel Programming 1 July 26th 05 03:17 PM
How can I insert 4000 rows of Excel data into a sql database skaty Excel Programming 0 July 31st 04 08:09 PM


All times are GMT +1. The time now is 05:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"